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());
}
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);
}
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);
}
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;
}
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;
}
Aggregations