Search in sources :

Example 81 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class PostIntegrationTest method testEditPostByChangingContext3_asTutor.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void testEditPostByChangingContext3_asTutor() throws Exception {
    // update course-wide post
    Post postToUpdate = existingCourseWidePosts.get(0);
    // change to context to lecture
    postToUpdate.setCourseWideContext(null);
    postToUpdate.setCourse(null);
    postToUpdate.setLecture(this.existingLecturePosts.get(0).getLecture());
    Post updatedPost = request.putWithResponseBody("/api/courses/" + courseId + "/posts/" + postToUpdate.getId(), postToUpdate, Post.class, HttpStatus.OK);
    database.assertSensitiveInformationHidden(updatedPost);
    assertThat(updatedPost).isEqualTo(postToUpdate);
}
Also used : Post(de.tum.in.www1.artemis.domain.metis.Post) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 82 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class PostIntegrationTest method testCreateExamExercisePost_badRequest.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateExamExercisePost_badRequest() throws Exception {
    Exam exam = database.setupSimpleExamWithExerciseGroupExercise(course);
    Post postToSave = createPostWithoutContext();
    Exercise examExercise = exam.getExerciseGroups().get(0).getExercises().stream().findFirst().orElseThrow();
    postToSave.setExercise(examExercise);
    request.postWithResponseBody("/api/courses/" + courseId + "/posts", postToSave, Post.class, HttpStatus.BAD_REQUEST);
    assertThat(existingExercisePosts).hasSameSizeAs(postRepository.findPostsByExerciseId(exerciseId, false, false, false, null));
    verify(groupNotificationService, times(0)).notifyAllGroupsAboutNewPostForExercise(any(), any());
}
Also used : Exercise(de.tum.in.www1.artemis.domain.Exercise) Post(de.tum.in.www1.artemis.domain.metis.Post) Exam(de.tum.in.www1.artemis.domain.exam.Exam) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 83 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class PostIntegrationTest method testEditPost_forbidden.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testEditPost_forbidden() throws Exception {
    // update own post (index 0)--> OK
    Post postToUpdate = editExistingPost(existingPosts.get(0));
    Post updatedPost = request.putWithResponseBody("/api/courses/" + courseId + "/posts/" + postToUpdate.getId(), postToUpdate, Post.class, HttpStatus.OK);
    database.assertSensitiveInformationHidden(updatedPost);
    assertThat(updatedPost).isEqualTo(postToUpdate);
    // update post from another student (index 1)--> forbidden
    Post postToNotUpdate = editExistingPost(existingPosts.get(1));
    Post notUpdatedPost = request.putWithResponseBody("/api/courses/" + courseId + "/posts/" + postToNotUpdate.getId(), postToNotUpdate, Post.class, HttpStatus.FORBIDDEN);
    assertThat(notUpdatedPost).isNull();
}
Also used : Post(de.tum.in.www1.artemis.domain.metis.Post) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 84 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class PostIntegrationTest method testEditPostWithIdIsNull_badRequest.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testEditPostWithIdIsNull_badRequest() throws Exception {
    Post postToUpdate = existingPosts.get(0);
    postToUpdate.setId(null);
    Post updatedPost = request.putWithResponseBody("/api/courses/" + courseId + "/posts/" + postToUpdate.getId(), postToUpdate, Post.class, HttpStatus.BAD_REQUEST);
    assertThat(updatedPost).isNull();
}
Also used : Post(de.tum.in.www1.artemis.domain.metis.Post) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 85 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class PostIntegrationTest method testPinPost_asStudent_forbidden.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testPinPost_asStudent_forbidden() throws Exception {
    Post postToNotPin = editExistingPost(existingPosts.get(1));
    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("displayPriority", DisplayPriority.PINNED.toString());
    // try to change display priority to PINNED
    Post notUpdatedPost = request.putWithResponseBodyAndParams("/api/courses/" + courseId + "/posts/" + postToNotPin.getId() + "/display-priority", null, Post.class, HttpStatus.FORBIDDEN, params);
    assertThat(notUpdatedPost).isNull();
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Post(de.tum.in.www1.artemis.domain.metis.Post) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Aggregations

Post (de.tum.in.www1.artemis.domain.metis.Post)155 WithMockUser (org.springframework.security.test.context.support.WithMockUser)150 Test (org.junit.jupiter.api.Test)136 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)118 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)97 User (de.tum.in.www1.artemis.domain.User)88 AnswerPost (de.tum.in.www1.artemis.domain.metis.AnswerPost)87 URI (java.net.URI)63 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)56 Course (de.tum.in.www1.artemis.domain.Course)52 Transactional (org.springframework.transaction.annotation.Transactional)37 Reaction (de.tum.in.www1.artemis.domain.metis.Reaction)36 Test (org.junit.Test)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)36 Exercise (de.tum.in.www1.artemis.domain.Exercise)35 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24 Exam (de.tum.in.www1.artemis.domain.exam.Exam)20 Lecture (de.tum.in.www1.artemis.domain.Lecture)16 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)16 SortingOrder (de.tum.in.www1.artemis.domain.enumeration.SortingOrder)16