Search in sources :

Example 16 with TextUnit

use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project ArTEMiS by ls1intum.

the class TextUnitIntegrationTest method updateTextUnit_noId_shouldReturnBadRequest.

@Test
@WithMockUser(username = "editor1", roles = "EDITOR")
public void updateTextUnit_noId_shouldReturnBadRequest() throws Exception {
    persistTextUnitWithLecture();
    TextUnit textUnitFromRequest = request.get("/api/lectures/" + lecture.getId() + "/text-units/" + this.textUnit.getId(), HttpStatus.OK, TextUnit.class);
    textUnitFromRequest.setId(null);
    request.putWithResponseBody("/api/lectures/" + lecture.getId() + "/text-units", textUnitFromRequest, TextUnit.class, HttpStatus.BAD_REQUEST);
    request.get("/api/lectures/" + "2379812738912" + "/text-units/" + this.textUnit.getId(), HttpStatus.CONFLICT, TextUnit.class);
}
Also used : TextUnit(de.tum.in.www1.artemis.domain.lecture.TextUnit) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 17 with TextUnit

use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project ArTEMiS by ls1intum.

the class TextUnitIntegrationTest method getTextUnit_correctId_shouldReturnTextUnit.

@Test
@WithMockUser(username = "editor1", roles = "EDITOR")
public void getTextUnit_correctId_shouldReturnTextUnit() throws Exception {
    persistTextUnitWithLecture();
    TextUnit textUnitFromRequest = request.get("/api/lectures/" + lecture.getId() + "/text-units/" + this.textUnit.getId(), HttpStatus.OK, TextUnit.class);
    assertThat(this.textUnit.getId()).isEqualTo(textUnitFromRequest.getId());
}
Also used : TextUnit(de.tum.in.www1.artemis.domain.lecture.TextUnit) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 18 with TextUnit

use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project ArTEMiS by ls1intum.

the class TextUnitIntegrationTest method createTextUnit_EditorNotInCourse_shouldReturnForbidden.

@Test
@WithMockUser(username = "editor42", roles = "EDITOR")
public void createTextUnit_EditorNotInCourse_shouldReturnForbidden() throws Exception {
    request.postWithResponseBody("/api/lectures/" + this.lecture.getId() + "/text-units", textUnit, TextUnit.class, HttpStatus.FORBIDDEN);
    request.postWithResponseBody("/api/lectures/" + "2379812738912" + "/text-units", textUnit, TextUnit.class, HttpStatus.BAD_REQUEST);
    textUnit.setLecture(new Lecture());
    request.postWithResponseBody("/api/lectures/" + this.lecture.getId() + "/text-units", textUnit, TextUnit.class, HttpStatus.CONFLICT);
    textUnit.setId(21312321L);
    request.postWithResponseBody("/api/lectures/" + this.lecture.getId() + "/text-units", textUnit, TextUnit.class, HttpStatus.BAD_REQUEST);
}
Also used : Lecture(de.tum.in.www1.artemis.domain.Lecture) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 19 with TextUnit

use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project ArTEMiS by ls1intum.

the class TextUnitIntegrationTest method initTestCase.

@BeforeEach
public void initTestCase() throws Exception {
    this.database.addUsers(1, 1, 1, 1);
    this.lecture = this.database.createCourseWithLecture(true);
    this.textUnit = new TextUnit();
    this.textUnit.setName("LoremIpsum");
    this.textUnit.setContent("This is a Test");
    // Add users that are not in the course
    userRepository.save(ModelFactory.generateActivatedUser("student42"));
    userRepository.save(ModelFactory.generateActivatedUser("tutor42"));
    userRepository.save(ModelFactory.generateActivatedUser("editor42"));
    userRepository.save(ModelFactory.generateActivatedUser("instructor42"));
}
Also used : TextUnit(de.tum.in.www1.artemis.domain.lecture.TextUnit) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with TextUnit

use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project ArTEMiS by ls1intum.

the class LearningGoalIntegrationTest method creatingLectureUnitsOfLectureTwo.

private void creatingLectureUnitsOfLectureTwo() {
    // creating lecture units for lecture one
    TextUnit textUnit = new TextUnit();
    textUnit.setName("TextUnitOfLectureTwo");
    textUnit = textUnitRepository.save(textUnit);
    idOfTextUnitOfLectureTwo = textUnit.getId();
    Exercise textExercise = exerciseRepository.findById(idOfTextExercise).get();
    ExerciseUnit textExerciseUnit = new ExerciseUnit();
    textExerciseUnit.setExercise(textExercise);
    textExerciseUnit = exerciseUnitRepository.save(textExerciseUnit);
    idOfExerciseUnitTextOfLectureTwo = textExerciseUnit.getId();
    Exercise modelingExercise = exerciseRepository.findById(idOfModelingExercise).get();
    ExerciseUnit modelingExerciseUnit = new ExerciseUnit();
    modelingExerciseUnit.setExercise(modelingExercise);
    modelingExerciseUnit = exerciseUnitRepository.save(modelingExerciseUnit);
    idOfExerciseUnitModelingOfLectureTwo = modelingExerciseUnit.getId();
    List<LectureUnit> lectureUnitsOfLectureTwo = List.of(textUnit, textExerciseUnit, modelingExerciseUnit);
    Lecture lectureTwo = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoals(idOfLectureTwo).get();
    for (LectureUnit lectureUnit : lectureUnitsOfLectureTwo) {
        lectureTwo.addLectureUnit(lectureUnit);
    }
    lectureRepository.save(lectureTwo);
}
Also used : QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) TextUnit(de.tum.in.www1.artemis.domain.lecture.TextUnit)

Aggregations

TextUnit (de.tum.in.www1.artemis.domain.lecture.TextUnit)26 Test (org.junit.jupiter.api.Test)14 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 LectureUnit (de.tum.in.www1.artemis.domain.lecture.LectureUnit)8 ConflictException (de.tum.in.www1.artemis.web.rest.errors.ConflictException)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Lecture (de.tum.in.www1.artemis.domain.Lecture)4 ExerciseUnit (de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)4 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)4 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)4 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Attachment (de.tum.in.www1.artemis.domain.Attachment)2 Course (de.tum.in.www1.artemis.domain.Course)2 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)2 URI (java.net.URI)2