Search in sources :

Example 1 with Post

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

the class AnswerPostIntegrationTest method testCreateAnswerPostInExercise.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateAnswerPostInExercise() throws Exception {
    AnswerPost answerPostToSave = createAnswerPost(existingPostsWithAnswersInExercise.get(0));
    AnswerPost createdAnswerPost = request.postWithResponseBody("/api/courses/" + courseId + "/answer-posts", answerPostToSave, AnswerPost.class, HttpStatus.CREATED);
    // should not be automatically post resolving
    assertThat(createdAnswerPost.doesResolvePost()).isFalse();
    checkCreatedAnswerPost(answerPostToSave, createdAnswerPost);
    assertThat(existingAnswerPosts.size() + 1).isEqualTo(answerPostRepository.count());
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 2 with Post

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

the class AnswerPostIntegrationTest method testEditAnswerPost_asTutor.

// UPDATE
@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void testEditAnswerPost_asTutor() throws Exception {
    // update post of student1 (index 0)--> OK
    AnswerPost answerPostToUpdate = editExistingAnswerPost(existingAnswerPosts.get(0));
    AnswerPost updatedAnswerPost = request.putWithResponseBody("/api/courses/" + courseId + "/answer-posts/" + answerPostToUpdate.getId(), answerPostToUpdate, AnswerPost.class, HttpStatus.OK);
    assertThat(answerPostToUpdate).isEqualTo(updatedAnswerPost);
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 3 with Post

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

the class AnswerPostIntegrationTest method testDeleteAnswerPost_asTutor.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void testDeleteAnswerPost_asTutor() throws Exception {
    // delete post from another student (index 0) --> ok
    AnswerPost answerPostToDelete = existingAnswerPosts.get(0);
    request.delete("/api/courses/" + courseId + "/answer-posts/" + answerPostToDelete.getId(), HttpStatus.OK);
    assertThat(answerPostRepository.count()).isEqualTo(existingAnswerPosts.size() - 1);
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 4 with Post

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

the class AnswerPostIntegrationTest method testCreateAnswerPostCourseWide.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateAnswerPostCourseWide() throws Exception {
    AnswerPost answerPostToSave = createAnswerPost(existingPostsWithAnswersCourseWide.get(0));
    AnswerPost createdAnswerPost = request.postWithResponseBody("/api/courses/" + courseId + "/answer-posts", answerPostToSave, AnswerPost.class, HttpStatus.CREATED);
    // should not be automatically post resolving
    assertThat(createdAnswerPost.doesResolvePost()).isFalse();
    checkCreatedAnswerPost(answerPostToSave, createdAnswerPost);
    assertThat(existingAnswerPosts.size() + 1).isEqualTo(answerPostRepository.count());
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 5 with Post

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

the class AnswerPostIntegrationTest method createAnswerPost.

// HELPER METHODS
private AnswerPost createAnswerPost(Post post) {
    AnswerPost answerPost = new AnswerPost();
    answerPost.setContent("Content Answer Post");
    answerPost.setPost(post);
    post.addAnswerPost(answerPost);
    return answerPost;
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost)

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