Search in sources :

Example 1 with BehavioralSolutionEntryGenerationException

use of de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralSolutionEntryGenerationException in project ArTEMiS by ls1intum.

the class ProgrammingExerciseSolutionEntryResource method createBehavioralSolutionEntries.

/**
 * POST programming-exercises/:exerciseId/behavioral-solution-entries : Create the behavioral solution entries for a programming exercise
 *
 * @param exerciseId of the exercise
 * @return the {@link ResponseEntity} with status {@code 200} and with body the created solution entries,
 */
@PostMapping("programming-exercises/{exerciseId}/behavioral-solution-entries")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<ProgrammingExerciseSolutionEntry>> createBehavioralSolutionEntries(@PathVariable Long exerciseId) {
    log.debug("REST request to create behavioral solution entries");
    ProgrammingExercise exercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationElseThrow(exerciseId);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, exercise, null);
    try {
        var solutionEntries = behavioralTestCaseService.generateBehavioralSolutionEntries(exercise);
        return ResponseEntity.ok(solutionEntries);
    } catch (BehavioralSolutionEntryGenerationException e) {
        log.error("Unable to create behavioral solution entries", e);
        throw new InternalServerErrorException(e.getMessage());
    }
}
Also used : ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) InternalServerErrorException(de.tum.in.www1.artemis.web.rest.errors.InternalServerErrorException) BehavioralSolutionEntryGenerationException(de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralSolutionEntryGenerationException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with BehavioralSolutionEntryGenerationException

use of de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralSolutionEntryGenerationException in project ArTEMiS by ls1intum.

the class CombineChangeBlocksTest method testCombineManyIntoOne2.

@Test
public void testCombineManyIntoOne2() throws BehavioralSolutionEntryGenerationException {
    var changeBlocks = new ChangeBlock[] { new ChangeBlock(List.of(1, 2, 3)), new ChangeBlock(List.of(3, 4, 5)), new ChangeBlock(List.of(4, 5, 6)), new ChangeBlock(List.of(7, 8, 9)) };
    groupedFile.setCommonChanges(List.of(changeBlocks));
    assertThat(combineChangeBlocks.executeCondition()).isTrue();
    assertThat(combineChangeBlocks.executeAction()).isTrue();
    assertThat(groupedFile.getCommonChanges()).containsExactly(new ChangeBlock(List.of(1, 2, 3, 4, 5, 6, 7, 8, 9)));
}
Also used : ChangeBlock(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock) Test(org.junit.jupiter.api.Test)

Example 3 with BehavioralSolutionEntryGenerationException

use of de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralSolutionEntryGenerationException in project Artemis by ls1intum.

the class ProgrammingExerciseSolutionEntryResource method createBehavioralSolutionEntries.

/**
 * POST programming-exercises/:exerciseId/behavioral-solution-entries : Create the behavioral solution entries for a programming exercise
 *
 * @param exerciseId of the exercise
 * @return the {@link ResponseEntity} with status {@code 200} and with body the created solution entries,
 */
@PostMapping("programming-exercises/{exerciseId}/behavioral-solution-entries")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<ProgrammingExerciseSolutionEntry>> createBehavioralSolutionEntries(@PathVariable Long exerciseId) {
    log.debug("REST request to create behavioral solution entries");
    ProgrammingExercise exercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationElseThrow(exerciseId);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, exercise, null);
    try {
        var solutionEntries = behavioralTestCaseService.generateBehavioralSolutionEntries(exercise);
        return ResponseEntity.ok(solutionEntries);
    } catch (BehavioralSolutionEntryGenerationException e) {
        log.error("Unable to create behavioral solution entries", e);
        throw new InternalServerErrorException(e.getMessage());
    }
}
Also used : ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) InternalServerErrorException(de.tum.in.www1.artemis.web.rest.errors.InternalServerErrorException) BehavioralSolutionEntryGenerationException(de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralSolutionEntryGenerationException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with BehavioralSolutionEntryGenerationException

use of de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralSolutionEntryGenerationException in project Artemis by ls1intum.

the class CombineChangeBlocksTest method testCombineManyIntoOne1.

@Test
public void testCombineManyIntoOne1() throws BehavioralSolutionEntryGenerationException {
    var changeBlocks = new ChangeBlock[] { new ChangeBlock(List.of(2)), new ChangeBlock(List.of(3)), new ChangeBlock(List.of(4)), new ChangeBlock(List.of(5)) };
    groupedFile.setCommonChanges(List.of(changeBlocks));
    assertThat(combineChangeBlocks.executeCondition()).isTrue();
    assertThat(combineChangeBlocks.executeAction()).isTrue();
    assertThat(groupedFile.getCommonChanges()).containsExactly(new ChangeBlock(List.of(2, 3, 4, 5)));
}
Also used : ChangeBlock(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock) Test(org.junit.jupiter.api.Test)

Example 5 with BehavioralSolutionEntryGenerationException

use of de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralSolutionEntryGenerationException in project Artemis by ls1intum.

the class CombineChangeBlocksTest method testOneCombination2.

@Test
public void testOneCombination2() throws BehavioralSolutionEntryGenerationException {
    var changeBlocks = new ChangeBlock[] { new ChangeBlock(List.of(1, 2, 3, 4)), new ChangeBlock(List.of(3, 4, 5, 6, 7, 8)) };
    groupedFile.setCommonChanges(List.of(changeBlocks));
    assertThat(combineChangeBlocks.executeCondition()).isTrue();
    assertThat(combineChangeBlocks.executeAction()).isTrue();
    assertThat(groupedFile.getCommonChanges()).containsExactly(new ChangeBlock(List.of(1, 2, 3, 4, 5, 6, 7, 8)));
}
Also used : ChangeBlock(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock) Test(org.junit.jupiter.api.Test)

Aggregations

ChangeBlock (de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock)8 Test (org.junit.jupiter.api.Test)8 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)4 BehavioralSolutionEntryGenerationException (de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralSolutionEntryGenerationException)4 GroupedFile (de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile)4 ProgrammingExerciseSolutionEntry (de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseSolutionEntry)2 ProgrammingExerciseTestCaseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseTestCaseRepository)2 SolutionProgrammingExerciseParticipationRepository (de.tum.in.www1.artemis.repository.SolutionProgrammingExerciseParticipationRepository)2 ProgrammingExerciseSolutionEntryRepository (de.tum.in.www1.artemis.repository.hestia.ProgrammingExerciseSolutionEntryRepository)2 RepositoryService (de.tum.in.www1.artemis.service.RepositoryService)2 GitService (de.tum.in.www1.artemis.service.connectors.GitService)2 ProgrammingExerciseGitDiffReportService (de.tum.in.www1.artemis.service.hestia.ProgrammingExerciseGitDiffReportService)2 TestwiseCoverageService (de.tum.in.www1.artemis.service.hestia.TestwiseCoverageService)2 de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource (de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource)2 InternalServerErrorException (de.tum.in.www1.artemis.web.rest.errors.InternalServerErrorException)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 Logger (org.slf4j.Logger)2