Search in sources :

Example 1 with PostSortCriterion

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

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

the class PostIntegrationTest method testGetPostsForCourse_OrderByCreationDateDESC.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetPostsForCourse_OrderByCreationDateDESC() throws Exception {
    PostSortCriterion sortCriterion = PostSortCriterion.CREATION_DATE;
    SortingOrder sortingOrder = SortingOrder.DESCENDING;
    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);
    database.assertSensitiveInformationHidden(returnedPosts);
    existingPosts.sort(Comparator.comparing(Post::getCreationDate).reversed());
    assertThat(returnedPosts).isEqualTo(existingPosts);
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) 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 3 with PostSortCriterion

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

the class ReactionIntegrationTest method testGetPostsForCourse_OrderByVoteCountDESC.

// GET
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetPostsForCourse_OrderByVoteCountDESC() throws Exception {
    PostSortCriterion sortCriterion = PostSortCriterion.VOTES;
    SortingOrder sortingOrder = SortingOrder.DESCENDING;
    User student1 = database.getUserByLogin("student1");
    User student2 = database.getUserByLogin("student2");
    // student 1 is the author of the post and reacts on this post
    Post postReactedOn = existingPostsWithAnswers.get(0);
    createVoteReactionOnPost(postReactedOn, student1);
    Post postReactedOn2 = existingPostsWithAnswers.get(1);
    createVoteReactionOnPost(postReactedOn2, student1);
    createVoteReactionOnPost(postReactedOn2, 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()).reversed());
    assertThat(returnedPosts).isEqualTo(existingPostsWithAnswers);
}
Also used : 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 4 with PostSortCriterion

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

the class AnswerPostIntegrationTest method testGetPostsForCourse_OrderByAnswerCountDESC.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetPostsForCourse_OrderByAnswerCountDESC() throws Exception {
    PostSortCriterion sortCriterion = PostSortCriterion.ANSWER_COUNT;
    SortingOrder sortingOrder = SortingOrder.DESCENDING;
    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);
    database.assertSensitiveInformationHidden(returnedPosts);
    existingPostsWithAnswers = existingPostsWithAnswers.stream().sorted(Comparator.comparing((Post post) -> post.getAnswers().size()).reversed()).toList();
    assertThat(returnedPosts).isEqualTo(existingPostsWithAnswers);
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) SortingOrder(de.tum.in.www1.artemis.domain.enumeration.SortingOrder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 5 with PostSortCriterion

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

the class AnswerPostIntegrationTest method testGetPostsForCourse_OrderByAnswerCountASC.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetPostsForCourse_OrderByAnswerCountASC() throws Exception {
    PostSortCriterion sortCriterion = PostSortCriterion.ANSWER_COUNT;
    SortingOrder sortingOrder = SortingOrder.ASCENDING;
    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);
    database.assertSensitiveInformationHidden(returnedPosts);
    existingPostsWithAnswers = existingPostsWithAnswers.stream().sorted(Comparator.comparing(post -> post.getAnswers().size())).toList();
    assertThat(returnedPosts).isEqualTo(existingPostsWithAnswers);
}
Also used : SortingOrder(de.tum.in.www1.artemis.domain.enumeration.SortingOrder) BeforeEach(org.junit.jupiter.api.BeforeEach) AnswerPostRepository(de.tum.in.www1.artemis.repository.metis.AnswerPostRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collection(java.util.Collection) Course(de.tum.in.www1.artemis.domain.Course) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) de.tum.in.www1.artemis.domain.metis(de.tum.in.www1.artemis.domain.metis) Comparator(java.util.Comparator) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) SortingOrder(de.tum.in.www1.artemis.domain.enumeration.SortingOrder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Aggregations

AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)12 SortingOrder (de.tum.in.www1.artemis.domain.enumeration.SortingOrder)12 Test (org.junit.jupiter.api.Test)12 WithMockUser (org.springframework.security.test.context.support.WithMockUser)12 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)12 Post (de.tum.in.www1.artemis.domain.metis.Post)8 PostSortCriterion (de.tum.in.www1.artemis.domain.metis.PostSortCriterion)8 User (de.tum.in.www1.artemis.domain.User)6 Course (de.tum.in.www1.artemis.domain.Course)4 AnswerPost (de.tum.in.www1.artemis.domain.metis.AnswerPost)4 Collection (java.util.Collection)4 Comparator (java.util.Comparator)4 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 AfterEach (org.junit.jupiter.api.AfterEach)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 HttpStatus (org.springframework.http.HttpStatus)4 VOTE_EMOJI_ID (de.tum.in.www1.artemis.config.Constants.VOTE_EMOJI_ID)2 de.tum.in.www1.artemis.domain.metis (de.tum.in.www1.artemis.domain.metis)2