Search in sources :

Example 1 with Reaction

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

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

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