Search in sources :

Example 86 with Post

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

the class PostIntegrationTest method testArchivePost_asTutor.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void testArchivePost_asTutor() throws Exception {
    Post postToArchive = editExistingPost(existingPosts.get(0));
    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("displayPriority", DisplayPriority.ARCHIVED.toString());
    // change display priority to ARCHIVED
    Post updatedPost = request.putWithResponseBodyAndParams("/api/courses/" + courseId + "/posts/" + postToArchive.getId() + "/display-priority", null, Post.class, HttpStatus.OK, params);
    database.assertSensitiveInformationHidden(updatedPost);
    assertThat(updatedPost).isEqualTo(postToArchive);
}
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)

Example 87 with Post

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

the class PostIntegrationTest method testCreateLecturePost.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateLecturePost() throws Exception {
    Post postToSave = createPostWithoutContext();
    Lecture lecture = existingLecturePosts.get(0).getLecture();
    postToSave.setLecture(lecture);
    Post createdPost = request.postWithResponseBody("/api/courses/" + courseId + "/posts", postToSave, Post.class, HttpStatus.CREATED);
    database.assertSensitiveInformationHidden(createdPost);
    checkCreatedPost(postToSave, createdPost);
    assertThat(existingLecturePosts).hasSize(postRepository.findPostsByLectureId(lectureId, false, false, false, null).size() - 1);
    verify(groupNotificationService, times(1)).notifyAllGroupsAboutNewPostForLecture(createdPost, course);
}
Also used : Lecture(de.tum.in.www1.artemis.domain.Lecture) 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 88 with Post

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

the class PostIntegrationTest method testCreateExistingPost_badRequest.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateExistingPost_badRequest() throws Exception {
    Post existingPostToSave = existingPosts.get(0);
    request.postWithResponseBody("/api/courses/" + courseId + "/posts", existingPostToSave, Post.class, HttpStatus.BAD_REQUEST);
    assertThat(existingPosts.size()).isEqualTo(postRepository.count());
    verify(groupNotificationService, times(0)).notifyAllGroupsAboutNewPostForExercise(any(), any());
}
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 89 with Post

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

the class PostIntegrationTest method testEditPostByChangingContext1_asTutor.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void testEditPostByChangingContext1_asTutor() throws Exception {
    // update exercise post
    Post postToUpdate = existingExercisePosts.get(0);
    // change to context to lecture
    postToUpdate.setExercise(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 90 with Post

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

the class PostIntegrationTest method testEditAnnouncement_asTutor_forbidden.

// UPDATE
@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void testEditAnnouncement_asTutor_forbidden() throws Exception {
    Post postToUpdate = editExistingPost(existingCourseWidePosts.get(0));
    // simulate as if it was an announcement
    postToUpdate.setCourseWideContext(CourseWideContext.ANNOUNCEMENT);
    Post notUpdatedPost = request.putWithResponseBody("/api/courses/" + courseId + "/posts/" + postToUpdate.getId(), postToUpdate, 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)

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