Search in sources :

Example 1 with SolutionProgrammingExerciseParticipation

use of de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation in project ArTEMiS by ls1intum.

the class UrlServiceTest method testUserIndependentRepositoryUrl.

@Test
public void testUserIndependentRepositoryUrl() {
    var solutionProgrammingExerciseParticipation = new SolutionProgrammingExerciseParticipation();
    solutionProgrammingExerciseParticipation.setRepositoryUrl(repositoryUrl1.toString());
    assertThat(solutionProgrammingExerciseParticipation.getUserIndependentRepositoryUrl()).isEqualTo("https://bitbucket.ase.in.tum.de/scm/EIST2016RME/RMEXERCISE-ab123cd");
    var templateProgrammingExerciseParticipation = new TemplateProgrammingExerciseParticipation();
    templateProgrammingExerciseParticipation.setRepositoryUrl(repositoryUrl2.toString());
    assertThat(templateProgrammingExerciseParticipation.getUserIndependentRepositoryUrl()).isEqualTo("https://repobruegge.in.tum.de/scm/EIST2016RME/RMEXERCISE-ab123cd.git");
    var studentParticipation1 = new ProgrammingExerciseStudentParticipation();
    studentParticipation1.setRepositoryUrl(repositoryUrl3.toString());
    assertThat(studentParticipation1.getUserIndependentRepositoryUrl()).isEqualTo("https://artemistest2gitlab.ase.in.tum.de/TESTADAPTER/testadapter-exercise.git");
    var studentParticipation2 = new ProgrammingExerciseStudentParticipation();
    studentParticipation2.setRepositoryUrl(repositoryUrl4.toString());
    assertThat(studentParticipation2.getUserIndependentRepositoryUrl()).isEqualTo("https://artemistest2gitlab.ase.in.tum.de/FTCSCAGRADING1/ftcscagrading1-username");
    assertThat(new ProgrammingExerciseStudentParticipation().getUserIndependentRepositoryUrl()).isNull();
    var studentParticipation3 = new ProgrammingExerciseStudentParticipation();
    studentParticipation3.setRepositoryUrl("http://localhost:8080/Assignment/rest/words/{name}/protection");
    assertThat(studentParticipation3.getUserIndependentRepositoryUrl()).isNull();
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) TemplateProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.TemplateProgrammingExerciseParticipation) SolutionProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 2 with SolutionProgrammingExerciseParticipation

use of de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation in project Artemis by ls1intum.

the class ProgrammingExerciseSimulationService method setupInitialSubmissionsAndResults.

/**
 * This method creates the template and solution submissions and results for the new exercise
 * These submissions and results are SIMULATIONS for the testing of programming exercises without a connection to
 * the VCS and Continuous Integration server
 * @param programmingExercise the new exercise
 * This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
 */
public void setupInitialSubmissionsAndResults(ProgrammingExercise programmingExercise) {
    var templateProgrammingExerciseParticipation = this.templateProgrammingExerciseParticipationRepository.findByProgrammingExerciseId(programmingExercise.getId()).orElseThrow(() -> new EntityNotFoundException("TemplateProgrammingExerciseParticipation with programming exercise with " + programmingExercise.getId() + " does not exist"));
    var solutionProgrammingExerciseParticipation = this.solutionProgrammingExerciseParticipationRepository.findByProgrammingExerciseId(programmingExercise.getId()).orElseThrow(() -> new EntityNotFoundException("SolutionProgrammingExerciseParticipation with programming exercise with " + programmingExercise.getId() + " does not exist"));
    String commitHashBase = VCSSimulationUtils.simulateCommitHash();
    Result templateResult = createSubmissionAndResult(templateProgrammingExerciseParticipation, commitHashBase);
    templateResult.setResultString("0 of 13 passed");
    templateResult.setScore(0D);
    resultRepository.save(templateResult);
    String commitHashSolution = VCSSimulationUtils.simulateCommitHash();
    Result solutionResult = createSubmissionAndResult(solutionProgrammingExerciseParticipation, commitHashSolution);
    solutionResult.setResultString("13 of 13 passed");
    solutionResult.setScore(100D);
    resultRepository.save(solutionResult);
}
Also used : EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) Result(de.tum.in.www1.artemis.domain.Result)

Example 3 with SolutionProgrammingExerciseParticipation

use of de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation in project ArTEMiS by ls1intum.

the class TestwiseCoverageService method getLineCountByFilePath.

/**
 * Returns the line count by file name for all files in the solution repository for the last submission.
 * @return line count by file name of files in the last submission's solution repository
 */
private Map<String, Integer> getLineCountByFilePath(ProgrammingSubmission submission) {
    try {
        var solutionParticipation = (SolutionProgrammingExerciseParticipation) submission.getParticipation();
        var solutionRepo = gitService.getOrCheckoutRepository(solutionParticipation.getVcsRepositoryUrl(), true);
        gitService.resetToOriginHead(solutionRepo);
        gitService.pullIgnoreConflicts(solutionRepo);
        var solutionFiles = repositoryService.getFilesWithContent(solutionRepo);
        var result = new HashMap<String, Integer>();
        solutionFiles.forEach((filePath, value) -> {
            // do not count lines for non-java files
            if (!filePath.endsWith(".java")) {
                return;
            }
            var lineCount = value.split("\n").length + 1;
            result.put(filePath, lineCount);
        });
        return result;
    } catch (GitAPIException e) {
        log.error("Exception while generating testwise coverage report", e);
        throw new InternalServerErrorException("Error while generating testwise coverage report: " + e.getMessage());
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) InternalServerErrorException(de.tum.in.www1.artemis.web.rest.errors.InternalServerErrorException) SolutionProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation)

Example 4 with SolutionProgrammingExerciseParticipation

use of de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation in project ArTEMiS by ls1intum.

the class ProgrammingExerciseSimulationService method setupInitialSubmissionsAndResults.

/**
 * This method creates the template and solution submissions and results for the new exercise
 * These submissions and results are SIMULATIONS for the testing of programming exercises without a connection to
 * the VCS and Continuous Integration server
 * @param programmingExercise the new exercise
 * This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
 */
public void setupInitialSubmissionsAndResults(ProgrammingExercise programmingExercise) {
    var templateProgrammingExerciseParticipation = this.templateProgrammingExerciseParticipationRepository.findByProgrammingExerciseId(programmingExercise.getId()).orElseThrow(() -> new EntityNotFoundException("TemplateProgrammingExerciseParticipation with programming exercise with " + programmingExercise.getId() + " does not exist"));
    var solutionProgrammingExerciseParticipation = this.solutionProgrammingExerciseParticipationRepository.findByProgrammingExerciseId(programmingExercise.getId()).orElseThrow(() -> new EntityNotFoundException("SolutionProgrammingExerciseParticipation with programming exercise with " + programmingExercise.getId() + " does not exist"));
    String commitHashBase = VCSSimulationUtils.simulateCommitHash();
    Result templateResult = createSubmissionAndResult(templateProgrammingExerciseParticipation, commitHashBase);
    templateResult.setResultString("0 of 13 passed");
    templateResult.setScore(0D);
    resultRepository.save(templateResult);
    String commitHashSolution = VCSSimulationUtils.simulateCommitHash();
    Result solutionResult = createSubmissionAndResult(solutionProgrammingExerciseParticipation, commitHashSolution);
    solutionResult.setResultString("13 of 13 passed");
    solutionResult.setScore(100D);
    resultRepository.save(solutionResult);
}
Also used : EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) Result(de.tum.in.www1.artemis.domain.Result)

Example 5 with SolutionProgrammingExerciseParticipation

use of de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation in project Artemis by ls1intum.

the class TestwiseCoverageService method getLineCountByFilePath.

/**
 * Returns the line count by file name for all files in the solution repository for the last submission.
 * @return line count by file name of files in the last submission's solution repository
 */
private Map<String, Integer> getLineCountByFilePath(ProgrammingSubmission submission) {
    try {
        var solutionParticipation = (SolutionProgrammingExerciseParticipation) submission.getParticipation();
        var solutionRepo = gitService.getOrCheckoutRepository(solutionParticipation.getVcsRepositoryUrl(), true);
        gitService.resetToOriginHead(solutionRepo);
        gitService.pullIgnoreConflicts(solutionRepo);
        var solutionFiles = repositoryService.getFilesWithContent(solutionRepo);
        var result = new HashMap<String, Integer>();
        solutionFiles.forEach((filePath, value) -> {
            // do not count lines for non-java files
            if (!filePath.endsWith(".java")) {
                return;
            }
            var lineCount = value.split("\n").length + 1;
            result.put(filePath, lineCount);
        });
        return result;
    } catch (GitAPIException e) {
        log.error("Exception while generating testwise coverage report", e);
        throw new InternalServerErrorException("Error while generating testwise coverage report: " + e.getMessage());
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) InternalServerErrorException(de.tum.in.www1.artemis.web.rest.errors.InternalServerErrorException) SolutionProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation)

Aggregations

SolutionProgrammingExerciseParticipation (de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation)4 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)2 Result (de.tum.in.www1.artemis.domain.Result)2 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)2 TemplateProgrammingExerciseParticipation (de.tum.in.www1.artemis.domain.participation.TemplateProgrammingExerciseParticipation)2 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)2 InternalServerErrorException (de.tum.in.www1.artemis.web.rest.errors.InternalServerErrorException)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 Test (org.junit.jupiter.api.Test)2