Search in sources :

Example 6 with Reaction

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

the class ReactionIntegrationTest method testCreateOwnAnswerPostReaction.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateOwnAnswerPostReaction() 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);
}
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 7 with Reaction

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

the class ReactionIntegrationTest method testValidateReactionConstraintViolation.

@Test
@WithMockUser(username = "student2", roles = "USER")
public void testValidateReactionConstraintViolation() throws Exception {
    Reaction invalidReaction = createInvalidReaction();
    request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", invalidReaction, Reaction.class, HttpStatus.BAD_REQUEST);
    Set<ConstraintViolation<Reaction>> constraintViolations = validator.validate(invalidReaction);
    assertThat(constraintViolations).hasSize(1);
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) 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 8 with Reaction

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

the class ReactionIntegrationTest method testGetPostsForCourse_OrderByVoteCountASC.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetPostsForCourse_OrderByVoteCountASC() throws Exception {
    PostSortCriterion sortCriterion = PostSortCriterion.VOTES;
    SortingOrder sortingOrder = SortingOrder.ASCENDING;
    User student1 = database.getUserByLogin("student1");
    User student2 = database.getUserByLogin("student2");
    Post postReactedOn = existingPostsWithAnswers.get(0);
    createVoteReactionOnPost(postReactedOn, student1);
    createVoteReactionOnPost(postReactedOn, student2);
    Post post2ReactedOn = existingPostsWithAnswers.get(1);
    createVoteReactionOnPost(post2ReactedOn, student2);
    // refresh posts after reactions are added
    existingPostsWithAnswers = postRepository.findPostsForCourse(courseId, null, false, false, false, null);
    var params = new LinkedMultiValueMap<String, String>();
    // ordering only available in course discussions page, where paging is enabled
    params.add("pagingEnabled", "true");
    params.add("page", "0");
    params.add("size", String.valueOf(MAX_POSTS_PER_PAGE));
    params.add("postSortCriterion", sortCriterion.toString());
    params.add("sortingOrder", sortingOrder.toString());
    List<Post> returnedPosts = request.getList("/api/courses/" + courseId + "/posts", HttpStatus.OK, Post.class, params);
    existingPostsWithAnswers.sort(Comparator.comparing((Post post) -> post.getReactions().stream().filter(reaction -> reaction.getEmojiId().equals(VOTE_EMOJI_ID)).count()));
    assertThat(returnedPosts).isEqualTo(existingPostsWithAnswers);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) PostSortCriterion(de.tum.in.www1.artemis.domain.metis.PostSortCriterion) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Course(de.tum.in.www1.artemis.domain.Course) Autowired(org.springframework.beans.factory.annotation.Autowired) PostRepository(de.tum.in.www1.artemis.repository.metis.PostRepository) VOTE_EMOJI_ID(de.tum.in.www1.artemis.config.Constants.VOTE_EMOJI_ID) UserRepository(de.tum.in.www1.artemis.repository.UserRepository) Post(de.tum.in.www1.artemis.domain.metis.Post) ReactionRepository(de.tum.in.www1.artemis.repository.metis.ReactionRepository) Validation(javax.validation.Validation) ConstraintViolation(javax.validation.ConstraintViolation) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Reaction(de.tum.in.www1.artemis.domain.metis.Reaction) SortingOrder(de.tum.in.www1.artemis.domain.enumeration.SortingOrder) Collection(java.util.Collection) Set(java.util.Set) Validator(javax.validation.Validator) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) User(de.tum.in.www1.artemis.domain.User) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Comparator(java.util.Comparator) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) User(de.tum.in.www1.artemis.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) Post(de.tum.in.www1.artemis.domain.metis.Post) SortingOrder(de.tum.in.www1.artemis.domain.enumeration.SortingOrder) PostSortCriterion(de.tum.in.www1.artemis.domain.metis.PostSortCriterion) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 9 with Reaction

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

the class ReactionIntegrationTest method createInvalidReaction.

private Reaction createInvalidReaction() {
    Reaction reaction = new Reaction();
    reaction.setEmojiId("smiley");
    reaction.setPost(existingPostsWithAnswers.get(0));
    reaction.setAnswerPost(existingAnswerPosts.get(0));
    return reaction;
}
Also used : Reaction(de.tum.in.www1.artemis.domain.metis.Reaction)

Example 10 with Reaction

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

the class ReactionIntegrationTest method testCreatePostReactions.

@Test
@WithMockUser(username = "student2", roles = "USER")
public void testCreatePostReactions() throws Exception {
    // student 1 is the author of the post and student 2 reacts on this 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