Search in sources :

Example 21 with Reaction

use of de.tum.in.www1.artemis.domain.metis.Reaction in project Artemis by ls1intum.

the class ReactionIntegrationTest method testCreateMultipleOwnPostReaction_internalServerError.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateMultipleOwnPostReaction_internalServerError() throws Exception {
    // student 1 is the author of the post and reacts on this post
    Post postReactedOn = existingPostsWithAnswers.get(0);
    Reaction reactionToSaveOnPost = createReactionOnPost(postReactedOn);
    Reaction createdReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnPost, Reaction.class, HttpStatus.CREATED);
    checkCreatedReaction(reactionToSaveOnPost, createdReaction);
    assertThat(postReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByPostId(postReactedOn.getId()).size() - 1);
    // try again
    request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnPost, Reaction.class, HttpStatus.INTERNAL_SERVER_ERROR);
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) Post(de.tum.in.www1.artemis.domain.metis.Post) 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 22 with Reaction

use of de.tum.in.www1.artemis.domain.metis.Reaction 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)

Example 23 with Reaction

use of de.tum.in.www1.artemis.domain.metis.Reaction 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 24 with Reaction

use of de.tum.in.www1.artemis.domain.metis.Reaction 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 25 with Reaction

use of de.tum.in.www1.artemis.domain.metis.Reaction in project Artemis by ls1intum.

the class ReactionIntegrationTest method createVoteReactionOnPost.

private Reaction createVoteReactionOnPost(Post postReactedOn, User user) {
    Reaction reaction = new Reaction();
    reaction.setUser(user);
    reaction.setEmojiId(VOTE_EMOJI_ID);
    reaction.setPost(postReactedOn);
    reactionRepository.save(reaction);
    return reaction;
}
Also used : Reaction(de.tum.in.www1.artemis.domain.metis.Reaction)

Aggregations

Reaction (de.tum.in.www1.artemis.domain.metis.Reaction)42 AnswerPost (de.tum.in.www1.artemis.domain.metis.AnswerPost)34 WithMockUser (org.springframework.security.test.context.support.WithMockUser)32 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)30 Test (org.junit.jupiter.api.Test)30 Post (de.tum.in.www1.artemis.domain.metis.Post)22 Course (de.tum.in.www1.artemis.domain.Course)10 User (de.tum.in.www1.artemis.domain.User)10 SortingOrder (de.tum.in.www1.artemis.domain.enumeration.SortingOrder)4 PostSortCriterion (de.tum.in.www1.artemis.domain.metis.PostSortCriterion)4 MetisPostDTO (de.tum.in.www1.artemis.web.websocket.dto.MetisPostDTO)4 ConstraintViolation (javax.validation.ConstraintViolation)4 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)4 VOTE_EMOJI_ID (de.tum.in.www1.artemis.config.Constants.VOTE_EMOJI_ID)2 Posting (de.tum.in.www1.artemis.domain.metis.Posting)2 UserRepository (de.tum.in.www1.artemis.repository.UserRepository)2 PostRepository (de.tum.in.www1.artemis.repository.metis.PostRepository)2 ReactionRepository (de.tum.in.www1.artemis.repository.metis.ReactionRepository)2 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)2 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)2