Search in sources :

Example 36 with Post

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

the class QuizExerciseResourceIntTest method createQuizExercise.

@Test
@Transactional
public void createQuizExercise() throws Exception {
    int databaseSizeBeforeCreate = quizExerciseRepository.findAll().size();
    // Create the QuizExercise
    restQuizExerciseMockMvc.perform(post("/api/quiz-exercises").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(quizExercise))).andExpect(status().isCreated());
    // Validate the QuizExercise in the database
    List<QuizExercise> quizExerciseList = quizExerciseRepository.findAll();
    assertThat(quizExerciseList).hasSize(databaseSizeBeforeCreate + 1);
    QuizExercise testQuizExercise = quizExerciseList.get(quizExerciseList.size() - 1);
    assertThat(testQuizExercise.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
    assertThat(testQuizExercise.getExplanation()).isEqualTo(DEFAULT_EXPLANATION);
    assertThat(testQuizExercise.isRandomizeQuestionOrder()).isEqualTo(DEFAULT_RANDOMIZE_QUESTION_ORDER);
    assertThat(testQuizExercise.getAllowedNumberOfAttempts()).isEqualTo(DEFAULT_ALLOWED_NUMBER_OF_ATTEMPTS);
    assertThat(testQuizExercise.isIsVisibleBeforeStart()).isEqualTo(DEFAULT_IS_VISIBLE_BEFORE_START);
    assertThat(testQuizExercise.isIsOpenForPractice()).isEqualTo(DEFAULT_IS_OPEN_FOR_PRACTICE);
    assertThat(testQuizExercise.isIsPlannedToStart()).isEqualTo(DEFAULT_IS_PLANNED_TO_START);
    assertThat(testQuizExercise.getDuration()).isEqualTo(DEFAULT_DURATION);
}
Also used : QuizExercise(de.tum.in.www1.artemis.domain.QuizExercise) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with Post

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

the class QuizSubmissionResourceIntTest method createQuizSubmission.

@Test
@Transactional
public void createQuizSubmission() throws Exception {
    int databaseSizeBeforeCreate = quizSubmissionRepository.findAll().size();
    // Create the QuizSubmission
    restQuizSubmissionMockMvc.perform(post("/api/quiz-submissions").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(quizSubmission))).andExpect(status().isCreated());
    // Validate the QuizSubmission in the database
    List<QuizSubmission> quizSubmissionList = quizSubmissionRepository.findAll();
    assertThat(quizSubmissionList).hasSize(databaseSizeBeforeCreate + 1);
    QuizSubmission testQuizSubmission = quizSubmissionList.get(quizSubmissionList.size() - 1);
    assertThat(testQuizSubmission.getScoreInPoints()).isEqualTo(DEFAULT_SCORE_IN_POINTS);
}
Also used : QuizSubmission(de.tum.in.www1.artemis.domain.QuizSubmission) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with Post

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

the class ResultResourceIntTest method createResult.

@Test
@Transactional
public void createResult() throws Exception {
    int databaseSizeBeforeCreate = resultRepository.findAll().size();
    // Create the Result
    restResultMockMvc.perform(post("/api/results").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(result))).andExpect(status().isCreated());
    // Validate the Result in the database
    List<Result> resultList = resultRepository.findAll();
    assertThat(resultList).hasSize(databaseSizeBeforeCreate + 1);
    Result testResult = resultList.get(resultList.size() - 1);
    assertThat(testResult.getResultString()).isEqualTo(DEFAULT_RESULT_STRING);
    assertThat(testResult.getCompletionDate()).isEqualTo(DEFAULT_COMPLETION_DATE);
    assertThat(testResult.isSuccessful()).isEqualTo(DEFAULT_SUCCESSFUL);
    assertThat(testResult.isBuildArtifact()).isEqualTo(DEFAULT_BUILD_ARTIFACT);
    assertThat(testResult.getScore()).isEqualTo(DEFAULT_SCORE);
    assertThat(testResult.isRated()).isEqualTo(DEFAULT_RATED);
    assertThat(testResult.getHasFeedback()).isEqualTo(DEFAULT_HAS_FEEDBACK);
}
Also used : Result(de.tum.in.www1.artemis.domain.Result) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with Post

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

the class UserResourceIntTest method createUserWithExistingEmail.

@Test
@Transactional
public void createUserWithExistingEmail() throws Exception {
    // Initialize the database
    userRepository.saveAndFlush(user);
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    Set<String> authorities = new HashSet<>();
    authorities.add(AuthoritiesConstants.USER);
    ManagedUserVM managedUserVM = new ManagedUserVM(null, "anotherlogin", DEFAULT_PASSWORD, DEFAULT_FIRSTNAME, DEFAULT_LASTNAME, // this email should already be used
    DEFAULT_EMAIL, true, DEFAULT_IMAGEURL, DEFAULT_LANGKEY, null, null, null, null, authorities, new ArrayList<String>());
    // Create the User
    restUserMockMvc.perform(post("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest());
    // Validate the User in the database
    List<User> userList = userRepository.findAll();
    assertThat(userList).hasSize(databaseSizeBeforeCreate);
}
Also used : User(de.tum.in.www1.artemis.domain.User) ManagedUserVM(de.tum.in.www1.artemis.web.rest.vm.ManagedUserVM) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with Post

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

the class FeedbackResource method createFeedback.

/**
 * POST  /feedbacks : Create a new feedback.
 *
 * @param feedback the feedback to create
 * @return the ResponseEntity with status 201 (Created) and with body the new feedback, or with status 400 (Bad Request) if the feedback has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/feedbacks")
@Timed
public ResponseEntity<Feedback> createFeedback(@RequestBody Feedback feedback) throws URISyntaxException {
    log.debug("REST request to save Feedback : {}", feedback);
    if (feedback.getId() != null) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new feedback cannot already have an ID")).body(null);
    }
    Feedback savedFeedback = feedbackService.save(feedback);
    return ResponseEntity.created(new URI("/api/feedbacks/" + savedFeedback.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, savedFeedback.getId().toString())).body(savedFeedback);
}
Also used : Feedback(de.tum.in.www1.artemis.domain.Feedback) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

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