Search in sources :

Example 11 with ExerciseHint

use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project ArTEMiS by ls1intum.

the class ExerciseHintIntegrationTest method updateHintAsInstructor.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateHintAsInstructor() throws Exception {
    ExerciseHint exerciseHint = exerciseHintRepository.findAll().get(0);
    String newContent = "new content value!";
    exerciseHint.setContent(newContent);
    request.put("/api/programming-exercises/" + exerciseHint.getExercise().getId() + "/exercise-hints/" + exerciseHint.getId(), exerciseHint, HttpStatus.OK);
    Optional<ExerciseHint> hintAfterSave = exerciseHintRepository.findById(exerciseHint.getId());
    assertThat(hintAfterSave).isPresent();
    assertThat(hintAfterSave.get()).isInstanceOf(ExerciseHint.class);
    assertThat((hintAfterSave.get()).getContent()).isEqualTo(newContent);
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 12 with ExerciseHint

use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project ArTEMiS by ls1intum.

the class ExerciseHintIntegrationTest method updateCodeHintTitle.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateCodeHintTitle() throws Exception {
    CodeHint codeHint = new CodeHint();
    codeHint.setTitle("Hint 1");
    codeHint.setExercise(exerciseLite);
    exerciseHintRepository.save(codeHint);
    codeHint.setTitle("New Title");
    request.put("/api/programming-exercises/" + codeHint.getExercise().getId() + "/exercise-hints/" + codeHint.getId(), codeHint, HttpStatus.OK);
    Optional<ExerciseHint> hintAfterSave = exerciseHintRepository.findById(codeHint.getId());
    assertThat(hintAfterSave).isPresent();
    assertThat(hintAfterSave.get()).isInstanceOf(CodeHint.class);
    assertThat((hintAfterSave.get()).getTitle()).isEqualTo("New Title");
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) CodeHint(de.tum.in.www1.artemis.domain.hestia.CodeHint) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 13 with ExerciseHint

use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project ArTEMiS by ls1intum.

the class ExerciseHintIntegrationTest method updateHintForbidden.

private void updateHintForbidden() throws Exception {
    ExerciseHint exerciseHint = exerciseHintRepository.findAll().get(0);
    String newContent = "new content value!";
    String contentBefore = exerciseHint.getContent();
    exerciseHint.setContent(newContent);
    request.put("/api/programming-exercises/" + exerciseHint.getExercise().getId() + "/exercise-hints/" + exerciseHint.getId(), exerciseHint, HttpStatus.FORBIDDEN);
    Optional<ExerciseHint> hintAfterSave = exerciseHintRepository.findById(exerciseHint.getId());
    assertThat(hintAfterSave).isPresent();
    assertThat(hintAfterSave.get()).isInstanceOf(ExerciseHint.class);
    assertThat((hintAfterSave.get()).getContent()).isEqualTo(contentBefore);
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint)

Example 14 with ExerciseHint

use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project ArTEMiS by ls1intum.

the class ExerciseHintIntegrationTest method createHintAsTutorForbidden.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void createHintAsTutorForbidden() throws Exception {
    ExerciseHint exerciseHint = new ExerciseHint().content("content 4").title("title 4").exercise(exerciseLite);
    request.post("/api/programming-exercises/" + exerciseHint.getExercise().getId() + "/exercise-hints/", exerciseHint, HttpStatus.FORBIDDEN);
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Example 15 with ExerciseHint

use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project ArTEMiS by ls1intum.

the class ExerciseHintIntegrationTest method createHintWithInvalidExerciseIds.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void createHintWithInvalidExerciseIds() throws Exception {
    Course course = database.addCourseWithOneProgrammingExercise();
    var unrelatedExercise = course.getExercises().stream().findFirst().orElseThrow();
    ExerciseHint exerciseHint = new ExerciseHint();
    exerciseHint.setTitle("Test Title");
    exerciseHint.setExercise(exerciseLite);
    request.post("/api/programming-exercises/" + unrelatedExercise.getId() + "/exercise-hints", exerciseHint, HttpStatus.CONFLICT);
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test)

Aggregations

ExerciseHint (de.tum.in.www1.artemis.domain.hestia.ExerciseHint)52 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)38 Test (org.junit.jupiter.api.Test)38 WithMockUser (org.springframework.security.test.context.support.WithMockUser)38 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 CodeHint (de.tum.in.www1.artemis.domain.hestia.CodeHint)10 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)8 ConflictException (de.tum.in.www1.artemis.web.rest.errors.ConflictException)8 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)6 Exercise (de.tum.in.www1.artemis.domain.Exercise)4 Feedback (de.tum.in.www1.artemis.domain.Feedback)2 Submission (de.tum.in.www1.artemis.domain.Submission)2 User (de.tum.in.www1.artemis.domain.User)2 ExerciseHintActivation (de.tum.in.www1.artemis.domain.hestia.ExerciseHintActivation)2 ProgrammingExerciseTask (de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTask)2 StudentParticipationRepository (de.tum.in.www1.artemis.repository.StudentParticipationRepository)2 ExerciseHintActivationRepository (de.tum.in.www1.artemis.repository.hestia.ExerciseHintActivationRepository)2 ExerciseHintRepository (de.tum.in.www1.artemis.repository.hestia.ExerciseHintRepository)2 Role (de.tum.in.www1.artemis.security.Role)2