Search in sources :

Example 1 with TextUnit

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

the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict() throws Exception {
    TextUnitList newlyOrderedList = new TextUnitList();
    newlyOrderedList.add(textUnit);
    newlyOrderedList.add(textUnit2);
    newlyOrderedList.add(textUnit3);
    for (TextUnit textUnit : newlyOrderedList) {
        textUnit.setLecture(null);
    }
    request.put("/api/lectures/" + lecture1.getId() + "/lecture-units-order", List.of(), HttpStatus.CONFLICT);
}
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 2 with TextUnit

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

the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder() throws Exception {
    long idOfOriginalFirstPosition = lecture1.getLectureUnits().get(0).getId();
    long idOfOriginalSecondPosition = lecture1.getLectureUnits().get(1).getId();
    TextUnitList newlyOrderedList = new TextUnitList();
    newlyOrderedList.add(textUnit);
    newlyOrderedList.add(textUnit2);
    for (TextUnit textUnit : newlyOrderedList) {
        textUnit.setLecture(null);
    }
    Collections.swap(newlyOrderedList, 0, 1);
    List<TextUnit> returnedList = request.putWithResponseBodyList("/api/lectures/" + lecture1.getId() + "/lecture-units-order", newlyOrderedList, TextUnit.class, HttpStatus.OK);
    assertThat(returnedList.get(0).getId()).isEqualTo(idOfOriginalSecondPosition);
    assertThat(returnedList.get(1).getId()).isEqualTo(idOfOriginalFirstPosition);
}
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 3 with TextUnit

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

the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder() throws Exception {
    long idOfOriginalFirstPosition = lecture1.getLectureUnits().get(0).getId();
    long idOfOriginalSecondPosition = lecture1.getLectureUnits().get(1).getId();
    TextUnitList newlyOrderedList = new TextUnitList();
    newlyOrderedList.add(textUnit);
    newlyOrderedList.add(textUnit2);
    for (TextUnit textUnit : newlyOrderedList) {
        textUnit.setLecture(null);
    }
    Collections.swap(newlyOrderedList, 0, 1);
    List<TextUnit> returnedList = request.putWithResponseBodyList("/api/lectures/" + lecture1.getId() + "/lecture-units-order", newlyOrderedList, TextUnit.class, HttpStatus.OK);
    assertThat(returnedList.get(0).getId()).isEqualTo(idOfOriginalSecondPosition);
    assertThat(returnedList.get(1).getId()).isEqualTo(idOfOriginalFirstPosition);
}
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 4 with TextUnit

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

the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict() throws Exception {
    TextUnitList newlyOrderedList = new TextUnitList();
    newlyOrderedList.add(textUnit);
    newlyOrderedList.add(textUnit2);
    newlyOrderedList.add(textUnit3);
    for (TextUnit textUnit : newlyOrderedList) {
        textUnit.setLecture(null);
    }
    request.put("/api/lectures/" + lecture1.getId() + "/lecture-units-order", List.of(), HttpStatus.CONFLICT);
}
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 5 with TextUnit

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

the class LectureImportService method cloneLectureUnit.

/**
 * This helper function clones the {@code importedLectureUnit} and returns it
 *
 * @param importedLectureUnit The original lecture unit to be copied
 * @param newLecture The new lecture to which the lecture units are appended
 * @return The cloned lecture unit
 */
private LectureUnit cloneLectureUnit(final LectureUnit importedLectureUnit, final Lecture newLecture) {
    log.debug("Creating a new LectureUnit from lecture unit {}", importedLectureUnit);
    if (importedLectureUnit instanceof TextUnit) {
        TextUnit textUnit = new TextUnit();
        textUnit.setName(importedLectureUnit.getName());
        textUnit.setReleaseDate(importedLectureUnit.getReleaseDate());
        textUnit.setContent(((TextUnit) importedLectureUnit).getContent());
        return textUnit;
    } else if (importedLectureUnit instanceof VideoUnit) {
        VideoUnit videoUnit = new VideoUnit();
        videoUnit.setName(importedLectureUnit.getName());
        videoUnit.setReleaseDate(importedLectureUnit.getReleaseDate());
        videoUnit.setDescription(((VideoUnit) importedLectureUnit).getDescription());
        videoUnit.setSource(((VideoUnit) importedLectureUnit).getSource());
        return videoUnit;
    } else if (importedLectureUnit instanceof AttachmentUnit) {
        // Create and save the attachment unit, then the attachment itself, as the id is needed for file handling
        AttachmentUnit attachmentUnit = new AttachmentUnit();
        attachmentUnit.setDescription(((AttachmentUnit) importedLectureUnit).getDescription());
        attachmentUnit.setLecture(newLecture);
        lectureUnitRepository.save(attachmentUnit);
        Attachment attachment = cloneAttachment(((AttachmentUnit) importedLectureUnit).getAttachment());
        attachment.setAttachmentUnit(attachmentUnit);
        attachmentRepository.save(attachment);
        attachmentUnit.setAttachment(attachment);
        return attachmentUnit;
    } else if (importedLectureUnit instanceof ExerciseUnit) {
        // We have a dedicated exercise import system, so this is left out for now
        return null;
    }
    return null;
}
Also used : Attachment(de.tum.in.www1.artemis.domain.Attachment)

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