Search in sources :

Example 1 with GitService

use of de.tum.in.www1.artemis.service.connectors.GitService in project ArTEMiS by ls1intum.

the class ExamIntegrationTest method testGenerateStudentExamsTemplateCombine.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testGenerateStudentExamsTemplateCombine() throws Exception {
    Exam examWithProgramming = database.addExerciseGroupsAndExercisesToExam(exam1, true);
    doNothing().when(gitService).combineAllCommitsOfRepositoryIntoOne(any());
    // invoke generate student exams
    request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + examWithProgramming.getId() + "/generate-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
    verify(gitService, times(1)).combineAllCommitsOfRepositoryIntoOne(any());
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 2 with GitService

use of de.tum.in.www1.artemis.service.connectors.GitService in project ArTEMiS by ls1intum.

the class ContinuousIntegrationTestService method setup.

/**
 * This method initializes the test case by setting up a local repo
 */
public void setup(MockDelegate mockDelegate, ContinuousIntegrationService continuousIntegrationService) throws Exception {
    this.mockDelegate = mockDelegate;
    this.continuousIntegrationService = continuousIntegrationService;
    database.addUsers(2, 0, 0, 0);
    database.addCourseWithOneProgrammingExercise();
    programmingExercise = programmingExerciseRepository.findAll().get(0);
    // init local repo
    String currentLocalFileName = "currentFileName";
    String currentLocalFileContent = "testContent";
    String currentLocalFolderName = "currentFolderName";
    localRepo.configureRepos("testLocalRepo", "testOriginRepo");
    // add file to the repository folder
    Path filePath = Path.of(localRepo.localRepoFile + "/" + currentLocalFileName);
    var file = Files.createFile(filePath).toFile();
    // write content to the created file
    FileUtils.write(file, currentLocalFileContent, Charset.defaultCharset());
    // add folder to the repository folder
    filePath = Path.of(localRepo.localRepoFile + "/" + currentLocalFolderName);
    Files.createDirectory(filePath).toFile();
    GitUtilService.MockFileRepositoryUrl localRepoUrl = new GitUtilService.MockFileRepositoryUrl(localRepo.localRepoFile);
    // create a participation
    participation = database.addStudentParticipationForProgrammingExerciseForLocalRepo(programmingExercise, "student1", localRepoUrl.getURI());
    assertThat(programmingExercise).as("Exercise was correctly set").isEqualTo(participation.getProgrammingExercise());
    // mock return of git path
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(localRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(participation.getVcsRepositoryUrl(), true);
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(localRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(participation.getVcsRepositoryUrl(), false);
}
Also used : Path(java.nio.file.Path) GitUtilService(de.tum.in.www1.artemis.util.GitUtilService)

Example 3 with GitService

use of de.tum.in.www1.artemis.service.connectors.GitService in project ArTEMiS by ls1intum.

the class TestRepositoryResourceIntegrationTest method testRenameFile_alreadyExists.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testRenameFile_alreadyExists() throws Exception {
    programmingExerciseRepository.save(programmingExercise);
    FileMove fileMove = createRenameFileMove();
    doReturn(Optional.empty()).when(gitService).getFileByName(any(), any());
    request.postWithoutLocation(testRepoBaseUrl + programmingExercise.getId() + "/rename-file", fileMove, HttpStatus.NOT_FOUND, null);
}
Also used : FileMove(de.tum.in.www1.artemis.web.rest.dto.FileMove) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 4 with GitService

use of de.tum.in.www1.artemis.service.connectors.GitService in project ArTEMiS by ls1intum.

the class HestiaUtilTestService method setupTemplate.

/**
 * Sets up the template repository of a programming exercise with specified files
 *
 * @param files        The fileNames mapped to the content of the files
 * @param exercise     The programming exercise
 * @param templateRepo The repository
 * @return The programming exercise
 */
public ProgrammingExercise setupTemplate(Map<String, String> files, ProgrammingExercise exercise, LocalRepository templateRepo) throws Exception {
    templateRepo.configureRepos("templateLocalRepo", "templateOriginRepo");
    for (Map.Entry<String, String> entry : files.entrySet()) {
        String fileName = entry.getKey();
        String content = entry.getValue();
        // add file to the repository folder
        Path filePath = Path.of(templateRepo.localRepoFile + "/" + fileName);
        Files.createDirectories(filePath.getParent());
        File solutionFile = Files.createFile(filePath).toFile();
        // write content to the created file
        FileUtils.write(solutionFile, content, Charset.defaultCharset());
    }
    var templateRepoUrl = new GitUtilService.MockFileRepositoryUrl(templateRepo.localRepoFile);
    exercise.setTemplateRepositoryUrl(templateRepoUrl.toString());
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(templateRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(templateRepoUrl, true);
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(templateRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(templateRepoUrl, false);
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(templateRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(eq(templateRepoUrl), eq(true), any());
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(templateRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(eq(templateRepoUrl), eq(false), any());
    bitbucketRequestMockProvider.enableMockingOfRequests(true);
    bitbucketRequestMockProvider.mockDefaultBranch(defaultBranch, urlService.getProjectKeyFromRepositoryUrl(templateRepoUrl));
    var savedExercise = exerciseRepository.save(exercise);
    database.addTemplateParticipationForProgrammingExercise(savedExercise);
    var templateParticipation = templateProgrammingExerciseParticipationRepository.findByProgrammingExerciseId(savedExercise.getId()).orElseThrow();
    templateParticipation.setRepositoryUrl(templateRepoUrl.toString());
    templateProgrammingExerciseParticipationRepository.save(templateParticipation);
    var templateSubmission = new ProgrammingSubmission();
    templateSubmission.setParticipation(templateParticipation);
    templateSubmission.setCommitHash(String.valueOf(files.hashCode()));
    programmingSubmissionRepository.save(templateSubmission);
    return savedExercise;
}
Also used : Path(java.nio.file.Path) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) Map(java.util.Map) File(java.io.File)

Example 5 with GitService

use of de.tum.in.www1.artemis.service.connectors.GitService in project ArTEMiS by ls1intum.

the class HestiaUtilTestService method setupSolution.

/**
 * Sets up the solution repository of a programming exercise with specified files
 *
 * @param files        The fileNames mapped to the content of the files
 * @param exercise     The programming exercise
 * @param solutionRepo The repository
 * @return The programming exercise
 */
public ProgrammingExercise setupSolution(Map<String, String> files, ProgrammingExercise exercise, LocalRepository solutionRepo) throws Exception {
    solutionRepo.configureRepos("solutionLocalRepo", "solutionOriginRepo");
    for (Map.Entry<String, String> entry : files.entrySet()) {
        String fileName = entry.getKey();
        String content = entry.getValue();
        // add file to the repository folder
        Path filePath = Path.of(solutionRepo.localRepoFile + "/" + fileName);
        Files.createDirectories(filePath.getParent());
        File solutionFile = Files.createFile(filePath).toFile();
        // write content to the created file
        FileUtils.write(solutionFile, content, Charset.defaultCharset());
    }
    var solutionRepoUrl = new GitUtilService.MockFileRepositoryUrl(solutionRepo.localRepoFile);
    exercise.setSolutionRepositoryUrl(solutionRepoUrl.toString());
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(solutionRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(solutionRepoUrl, true);
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(solutionRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(solutionRepoUrl, false);
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(solutionRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(eq(solutionRepoUrl), eq(true), any());
    doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(solutionRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(eq(solutionRepoUrl), eq(false), any());
    bitbucketRequestMockProvider.enableMockingOfRequests(true);
    bitbucketRequestMockProvider.mockDefaultBranch(defaultBranch, urlService.getProjectKeyFromRepositoryUrl(solutionRepoUrl));
    var savedExercise = exerciseRepository.save(exercise);
    database.addSolutionParticipationForProgrammingExercise(savedExercise);
    var solutionParticipation = solutionProgrammingExerciseParticipationRepository.findByProgrammingExerciseId(savedExercise.getId()).orElseThrow();
    solutionParticipation.setRepositoryUrl(solutionRepoUrl.toString());
    solutionProgrammingExerciseParticipationRepository.save(solutionParticipation);
    var solutionSubmission = new ProgrammingSubmission();
    solutionSubmission.setParticipation(solutionParticipation);
    solutionSubmission.setCommitHash(String.valueOf(files.hashCode()));
    programmingSubmissionRepository.save(solutionSubmission);
    return savedExercise;
}
Also used : Path(java.nio.file.Path) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) Map(java.util.Map) File(java.io.File)

Aggregations

Test (org.junit.jupiter.api.Test)34 WithMockUser (org.springframework.security.test.context.support.WithMockUser)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)18 Path (java.nio.file.Path)16 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)12 LocalRepository (de.tum.in.www1.artemis.util.LocalRepository)12 HttpHeaders (org.springframework.http.HttpHeaders)12 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)8 ProgrammingExerciseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository)8 GitUtilService (de.tum.in.www1.artemis.util.GitUtilService)8 ModelFactory (de.tum.in.www1.artemis.util.ModelFactory)8 FileMove (de.tum.in.www1.artemis.web.rest.dto.FileMove)8 ZonedDateTime (java.time.ZonedDateTime)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 AfterEach (org.junit.jupiter.api.AfterEach)8 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)8 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)8