Search in sources :

Example 96 with Post

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

the class ReactionIntegrationTest method testDeletePostReactionWithWrongCourseId_badRequest.

@Test
@WithMockUser(username = "student2", roles = "USER")
public void testDeletePostReactionWithWrongCourseId_badRequest() throws Exception {
    Course dummyCourse = database.createCourse();
    Post postToReactOn = existingPostsWithAnswers.get(0);
    Reaction reactionToSaveOnPost = createReactionOnPost(postToReactOn);
    request.delete("/api/courses/" + dummyCourse.getCourseIcon() + "/postings/reactions/" + reactionToSaveOnPost.getId(), HttpStatus.BAD_REQUEST);
    assertThat(postToReactOn.getReactions()).hasSameSizeAs(postRepository.findById(postToReactOn.getId()).get().getReactions());
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) Post(de.tum.in.www1.artemis.domain.metis.Post) Course(de.tum.in.www1.artemis.domain.Course) Reaction(de.tum.in.www1.artemis.domain.metis.Reaction) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 97 with Post

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

the class ReactionIntegrationTest method testCreateExistingReaction_badRequest.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateExistingReaction_badRequest() throws Exception {
    // student 1 is the author of the answer post and reacts on this answer post
    AnswerPost answerPostReactedOn = existingAnswerPosts.get(0);
    Reaction reactionToSaveOnAnswerPost = createReactionOnAnswerPost(answerPostReactedOn);
    Reaction createdReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnAnswerPost, Reaction.class, HttpStatus.CREATED);
    request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", createdReaction, Reaction.class, HttpStatus.BAD_REQUEST);
    checkCreatedReaction(reactionToSaveOnAnswerPost, createdReaction);
    assertThat(answerPostReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByAnswerPostId(answerPostReactedOn.getId()).size() - 1);
}
Also used : Reaction(de.tum.in.www1.artemis.domain.metis.Reaction) AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 98 with Post

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

the class ReactionIntegrationTest method testCreateMultipleOwnAnswerPostReaction_internalServerError.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateMultipleOwnAnswerPostReaction_internalServerError() throws Exception {
    // student 1 is the author of the answer post and reacts on this answer post
    AnswerPost answerPostReactedOn = existingAnswerPosts.get(0);
    Reaction reactionToSaveOnAnswerPost = createReactionOnAnswerPost(answerPostReactedOn);
    Reaction createdReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnAnswerPost, Reaction.class, HttpStatus.CREATED);
    checkCreatedReaction(reactionToSaveOnAnswerPost, createdReaction);
    assertThat(answerPostReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByAnswerPostId(answerPostReactedOn.getId()).size() - 1);
    // try again
    request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnAnswerPost, Reaction.class, HttpStatus.INTERNAL_SERVER_ERROR);
}
Also used : Reaction(de.tum.in.www1.artemis.domain.metis.Reaction) AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 99 with Post

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

the class ReactionIntegrationTest method saveReactionOfOtherUserOnPost.

private Reaction saveReactionOfOtherUserOnPost(Post postReactedOn) {
    Reaction reaction = new Reaction();
    reaction.setEmojiId("smiley");
    reaction.setPost(postReactedOn);
    Reaction savedReaction = reactionRepository.save(reaction);
    User user = userRepository.getUserWithGroupsAndAuthorities("student2");
    savedReaction.setUser(user);
    reactionRepository.save(savedReaction);
    return savedReaction;
}
Also used : User(de.tum.in.www1.artemis.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Reaction(de.tum.in.www1.artemis.domain.metis.Reaction)

Example 100 with Post

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

the class ReactionIntegrationTest method testCreateAnswerPostReactions.

@Test
@WithMockUser(username = "student2", roles = "USER")
public void testCreateAnswerPostReactions() throws Exception {
    // student 1 is the author of the answer post and student 2 reacts on this answer post
    AnswerPost answerPostReactedOn = existingAnswerPosts.get(0);
    Reaction reactionToSaveOnAnswerPost = createReactionOnAnswerPost(answerPostReactedOn);
    Reaction createdFirstReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnAnswerPost, Reaction.class, HttpStatus.CREATED);
    checkCreatedReaction(reactionToSaveOnAnswerPost, createdFirstReaction);
    assertThat(answerPostReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByAnswerPostId(answerPostReactedOn.getId()).size() - 1);
    // student 2 reacts again on this answer post
    reactionToSaveOnAnswerPost = createReactionOnAnswerPost(answerPostReactedOn);
    // change the emojiId to react differently
    reactionToSaveOnAnswerPost.setEmojiId("cry");
    Reaction createdSecondReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnAnswerPost, Reaction.class, HttpStatus.CREATED);
    checkCreatedReaction(reactionToSaveOnAnswerPost, createdSecondReaction);
    assertThat(answerPostReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByAnswerPostId(answerPostReactedOn.getId()).size() - 2);
}
Also used : Reaction(de.tum.in.www1.artemis.domain.metis.Reaction) AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) 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