Skip to content

Commit

Permalink
Development: Remove multiple occurrences of deprecated code (#8721)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianAnzinger authored Jun 4, 2024
1 parent b0d47b7 commit 7eed1c7
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ private static int getGitPartStartIndex(String urlString, Path urlPath) throws L
* <ul>
* <li>
* Input: Local repository path - {@code Paths.get("/local/path/projectX/my-repo/.git")}
* and Local VC server URL - {@code new URL("https://artemis.cit.tum.de")}
* and Local VC server URL - {@code new URI("https://artemis.cit.tum.de").getURL()}
* Output: {@code https://artemis.cit.tum.de/git/projectX/my-repo.git}
* </li>
* <li>
* Input: Remote repository path - {@code Paths.get("/remote/path/projectY/my-repo")}
* and Local VC server URL - {@code new URL("https://artemis.cit.tum.de")}
* and Local VC server URL - {@code new URI("https://artemis.cit.tum.de").getURL()}
* Output: {@code https://artemis.cit.tum.de/git/projectY/my-repo.git}
* </li>
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ void submitComplaintResponse_rejectComplaint() throws Exception {
Result storedResult = resultRepo.findWithBidirectionalSubmissionAndFeedbackAndAssessorAndAssessmentNoteAndTeamStudentsByIdElseThrow(modelingAssessment.getId());
Result updatedResult = storedResult.getSubmission().getLatestResult();
participationUtilService.checkFeedbackCorrectlyStored(modelingAssessment.getFeedbacks(), updatedResult.getFeedbacks(), FeedbackType.MANUAL);
assertThat(storedResult).as("only feedbacks are changed in the result").isEqualToIgnoringGivenFields(modelingAssessment, "feedbacks");
final String[] ignoringFields = { "feedbacks", "submission", "participation", "assessor" };
assertThat(storedResult).as("only feedbacks are changed in the result").usingRecursiveComparison().ignoringFields(ignoringFields).isEqualTo(modelingAssessment);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ void getSubmissionWithoutAssessment() throws Exception {
FileUploadSubmission storedSubmission = request.get("/api/exercises/" + releasedFileUploadExercise.getId() + "/file-upload-submission-without-assessment", HttpStatus.OK,
FileUploadSubmission.class);

assertThat(storedSubmission).as("in-time submission was found").isEqualToIgnoringGivenFields(submission, "results", "submissionDate", "fileService", "filePathService",
"entityFileService");
final String[] ignoringFields = { "results", "submissionDate", "fileService", "filePathService", "entityFileService", "participation" };
assertThat(storedSubmission).as("in-time submission was found").usingRecursiveComparison().ignoringFields(ignoringFields).isEqualTo(submission);
assertThat(storedSubmission.getSubmissionDate()).as("submission date is correct").isCloseTo(submission.getSubmissionDate(), HalfSecond());
assertThat(storedSubmission.getLatestResult()).as("result is not set").isNull();
checkDetailsHidden(storedSubmission, false);
Expand All @@ -342,8 +342,8 @@ void getLateSubmissionWithoutAssessment() throws Exception {
FileUploadSubmission storedSubmission = request.get("/api/exercises/" + releasedFileUploadExercise.getId() + "/file-upload-submission-without-assessment", HttpStatus.OK,
FileUploadSubmission.class);

assertThat(storedSubmission).as("submission was found").isEqualToIgnoringGivenFields(lateSubmission, "result", "submissionDate", "fileService", "filePathService",
"entityFileService");
final String[] ignoringFields = { "results", "submissionDate", "fileService", "filePathService", "entityFileService", "participation" };
assertThat(storedSubmission).as("submission was found").usingRecursiveComparison().ignoringFields(ignoringFields).isEqualTo(lateSubmission);
assertThat(storedSubmission.getLatestResult()).as("result is not set").isNull();
checkDetailsHidden(storedSubmission, false);
}
Expand All @@ -364,8 +364,8 @@ void testGetLateSubmissionWithoutAssessmentLock() throws Exception {
FileUploadSubmission storedSubmission = request.get("/api/exercises/" + releasedFileUploadExercise.getId() + "/file-upload-submission-without-assessment?lock=true",
HttpStatus.OK, FileUploadSubmission.class);

assertThat(storedSubmission).as("submission was found").isEqualToIgnoringGivenFields(lateSubmission, "results", "submissionDate", "fileService", "filePathService",
"entityFileService");
final String[] ignoringFields = { "results", "submissionDate", "fileService", "filePathService", "entityFileService", "participation" };
assertThat(storedSubmission).as("submission was found").usingRecursiveComparison().ignoringFields(ignoringFields).isEqualTo(lateSubmission);
assertThat(storedSubmission.getLatestResult()).as("result is set").isNotNull();
checkDetailsHidden(storedSubmission, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,10 +1054,12 @@ void testOverrideAutomaticAssessment_existingManualAssessmentDoesNotChange() thr

modelingAssessment = resultRepo.findDistinctWithFeedbackBySubmissionId(modelingSubmission2.getId()).orElseThrow();
assertThat(modelingAssessment.getFeedbacks()).as("assessment is correctly stored").hasSize(1);
assertThat(modelingAssessment.getFeedbacks().get(0)).as("feedback credits and text are correct").isEqualToComparingOnlyGivenFields(changedFeedback, "credits", "text");
assertThat(modelingAssessment.getFeedbacks().getFirst().getCredits()).as("feedback credits are correct").isEqualTo(changedFeedback.getCredits());
assertThat(modelingAssessment.getFeedbacks().getFirst().getText()).as("feedback text are correct").isEqualTo(changedFeedback.getText());
modelingAssessment = resultRepo.findDistinctWithFeedbackBySubmissionId(modelingSubmission.getId()).orElseThrow();
assertThat(modelingAssessment.getFeedbacks()).as("existing manual assessment has correct amount of feedback").hasSize(1);
assertThat(modelingAssessment.getFeedbacks().get(0)).as("existing manual assessment did not change").isEqualToComparingOnlyGivenFields(originalFeedback, "credits", "text");
assertThat(modelingAssessment.getFeedbacks().getFirst().getCredits()).as("existing manual assessment did not change credits").isEqualTo(originalFeedback.getCredits());
assertThat(modelingAssessment.getFeedbacks().getFirst().getText()).as("existing manual assessment did not change text").isEqualTo(originalFeedback.getText());
}

@Test
Expand All @@ -1080,11 +1082,12 @@ void testOverrideSubmittedManualAssessment_noConflict() throws Exception {

modelingAssessment = resultRepo.findDistinctWithFeedbackBySubmissionId(modelingSubmission.getId()).orElseThrow();
assertThat(modelingAssessment.getFeedbacks()).as("overridden assessment has correct amount of feedback").hasSize(1);
assertThat(modelingAssessment.getFeedbacks().get(0)).as("feedback is properly overridden").isEqualToComparingOnlyGivenFields(changedFeedback, "credits", "text");
assertThat(modelingAssessment.getFeedbacks().getFirst().getCredits()).as("feedback credits are properly overridden").isEqualTo(changedFeedback.getCredits());
assertThat(modelingAssessment.getFeedbacks().getFirst().getText()).as("feedback text is properly overridden").isEqualTo(changedFeedback.getText());
modelingAssessment = compassService.getSuggestionResult(modelingSubmission2, classExercise);
assertThat(modelingAssessment.getFeedbacks()).as("automatic assessment still exists").hasSize(1);
assertThat(modelingAssessment.getFeedbacks().get(0)).as("automatic assessment is overridden properly").isEqualToComparingOnlyGivenFields(changedFeedback, "credits",
"text");
assertThat(modelingAssessment.getFeedbacks().getFirst().getCredits()).as("automatic assessment credits are overridden properly").isEqualTo(changedFeedback.getCredits());
assertThat(modelingAssessment.getFeedbacks().getFirst().getText()).as("automatic assessment text is overridden properly").isEqualTo(changedFeedback.getText());
}

@Test
Expand Down Expand Up @@ -1112,10 +1115,12 @@ void testOverrideSubmittedManualAssessment_conflict() throws Exception {

modelingAssessment = resultRepo.findDistinctWithFeedbackBySubmissionId(modelingSubmission.getId()).orElseThrow();
assertThat(modelingAssessment.getFeedbacks()).as("overridden assessment has correct amount of feedback").hasSize(2);
assertThat(modelingAssessment.getFeedbacks().get(0)).as("feedback is properly overridden").isEqualToComparingOnlyGivenFields(changedFeedback, "credits", "text");
assertThat(modelingAssessment.getFeedbacks().getFirst().getCredits()).as("feedback credits are properly overridden").isEqualTo(changedFeedback.getCredits());
assertThat(modelingAssessment.getFeedbacks().getFirst().getText()).as("feedback text is properly overridden").isEqualTo(changedFeedback.getText());
modelingAssessment = resultRepo.findDistinctWithFeedbackBySubmissionId(modelingSubmission2.getId()).orElseThrow();
assertThat(modelingAssessment.getFeedbacks()).as("existing submitted assessment still exists").hasSize(2);
assertThat(modelingAssessment.getFeedbacks().get(0)).as("existing feedback is still the same").isEqualToComparingOnlyGivenFields(originalFeedback, "credits", "text");
assertThat(modelingAssessment.getFeedbacks().getFirst().getCredits()).as("existing feedback credits are still the same").isEqualTo(originalFeedback.getCredits());
assertThat(modelingAssessment.getFeedbacks().getFirst().getText()).as("existing feedback text is still the same").isEqualTo(originalFeedback.getText());
modelingAssessment = compassService.getSuggestionResult(modelingSubmission3, classExercise);
assertThat(modelingAssessment).as("automatic assessment is not possible").isNull();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ void getModelSubmissionWithoutAssessment() throws Exception {
ModelingSubmission storedSubmission = request.get("/api/exercises/" + classExercise.getId() + "/modeling-submission-without-assessment", HttpStatus.OK,
ModelingSubmission.class);

assertThat(storedSubmission).as("submission was found").isEqualToIgnoringGivenFields(submission, "results", "submissionDate");
assertThat(storedSubmission).as("submission was found").usingRecursiveComparison().ignoringFields("results", "submissionDate", "participation").isEqualTo(submission);
assertThat(storedSubmission.getSubmissionDate()).as("submission date is correct").isCloseTo(submission.getSubmissionDate(), HalfSecond());
assertThat(storedSubmission.getLatestResult()).as("result is not set").isNull();
checkDetailsHidden(storedSubmission, false);
Expand Down Expand Up @@ -630,7 +630,8 @@ void getModelSubmissionWithoutAssessment_lockSubmission() throws Exception {
// set dates to UTC and round to milliseconds for comparison
submission.setSubmissionDate(ZonedDateTime.ofInstant(submission.getSubmissionDate().truncatedTo(ChronoUnit.SECONDS).toInstant(), ZoneId.of("UTC")));
storedSubmission.setSubmissionDate(ZonedDateTime.ofInstant(storedSubmission.getSubmissionDate().truncatedTo(ChronoUnit.SECONDS).toInstant(), ZoneId.of("UTC")));
assertThat(storedSubmission).as("submission was found").isEqualToIgnoringGivenFields(submission, "results", "similarElementCounts");
final String[] ignoringFields = { "results", "submissionDate", "participation", "similarElementCounts" };
assertThat(storedSubmission).as("submission was found").usingRecursiveComparison().ignoringFields(ignoringFields).isEqualTo(submission);
assertThat(storedSubmission.getLatestResult()).as("result is set").isNotNull();
assertThat(storedSubmission.getLatestResult().getAssessor()).as("assessor is tutor1").isEqualTo(user);
checkDetailsHidden(storedSubmission, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private int invokeMaven(boolean testwiseCoverageAnalysis) throws MavenInvocation
InvocationRequest mvnRequest = new DefaultInvocationRequest();
mvnRequest.setJavaHome(java17Home);
mvnRequest.setPomFile(testRepo.localRepoFile);
mvnRequest.setGoals(List.of("clean", "test"));
mvnRequest.addArgs(List.of("clean", "test"));
if (testwiseCoverageAnalysis) {
mvnRequest.addArg("-Pcoverage");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ void testGetProgrammingSubmissionWithoutAssessment() throws Exception {
String url = "/api/exercises/" + exercise.getId() + "/programming-submission-without-assessment";
ProgrammingSubmission storedSubmission = request.get(url, HttpStatus.OK, ProgrammingSubmission.class);

assertThat(storedSubmission).as("submission was found").isEqualToIgnoringGivenFields(submission, "results", "submissionDate");
final String[] ignoringFields = { "results", "submissionDate", "participation" };
assertThat(storedSubmission).as("submission was found").usingRecursiveComparison().ignoringFields(ignoringFields).isEqualTo(submission);
assertThat(storedSubmission.getSubmissionDate()).as("submission date is correct").isCloseTo(submission.getSubmissionDate(), HalfSecond());
assertThat(storedSubmission.getLatestResult()).as("result is not set").isNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Optional;
Expand Down Expand Up @@ -37,8 +38,8 @@ class JenkinsInternalUriServiceTest extends AbstractSpringIntegrationJenkinsGitl
void initTestCase() throws Exception {
vcsRepositoryUri = new VcsRepositoryUri("http://localhost:80/some-repo.git");
ciUrl = "http://localhost:8080/some-ci-path";
internalVcsUrl = new URL("http://1.2.3.4:123");
internalCiUrl = new URL("http://5.6.7.8:123");
internalVcsUrl = new URI("http://1.2.3.4:123").toURL();
internalCiUrl = new URI("http://5.6.7.8:123").toURL();
ReflectionTestUtils.setField(jenkinsInternalUrlService, "internalVcsUrl", Optional.empty());
ReflectionTestUtils.setField(jenkinsInternalUrlService, "internalCiUrl", Optional.empty());
}
Expand Down Expand Up @@ -93,8 +94,8 @@ void testGetCiUrlOnInternalCiUrl() {

@Test
void testGetUrlOnInternalUrlWithoutPort() throws Exception {
ReflectionTestUtils.setField(jenkinsInternalUrlService, "internalCiUrl", Optional.of(new URL("http://www.host.name.com/")));
ReflectionTestUtils.setField(jenkinsInternalUrlService, "internalVcsUrl", Optional.of(new URL("http://www.hostname.com/")));
ReflectionTestUtils.setField(jenkinsInternalUrlService, "internalCiUrl", Optional.of(new URI("http://www.host.name.com/").toURL()));
ReflectionTestUtils.setField(jenkinsInternalUrlService, "internalVcsUrl", Optional.of(new URI("http://www.hostname.com/").toURL()));

var newVcsUrl = jenkinsInternalUrlService.toInternalVcsUrl(vcsRepositoryUri);
assertThat(newVcsUrl).hasToString("http://www.hostname.com/some-repo.git");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -131,7 +132,7 @@ private void setupJavaFiles(final String content) throws IOException {
void testGetResourceFilePathFromJar() throws IOException, URISyntaxException {
ResourceLoader resourceLoader = mock(ResourceLoader.class);
Resource resource = mock(Resource.class);
URL resourceUrl = new URL("jar:file:/example.jar!/path/to/resource.txt");
URL resourceUrl = new URI("jar:file:/example.jar!/path/to/resource.txt").toURL();

// Mock the getResource() method.
doReturn(true).when(resource).exists();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import static org.mockito.Mockito.when;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
Expand Down Expand Up @@ -71,7 +72,7 @@ void tearDown() throws Exception {
}

@Test
void testPerformDeepLinking() throws MalformedURLException {
void testPerformDeepLinking() throws MalformedURLException, URISyntaxException {
createMockOidcIdToken();
when(tokenRetriever.createDeepLinkingJWT(anyString(), anyMap())).thenReturn("test_jwt");

Expand All @@ -83,7 +84,7 @@ void testPerformDeepLinking() throws MalformedURLException {
}

@Test
void testEmptyJwtBuildLtiDeepLinkResponse() throws MalformedURLException {
void testEmptyJwtBuildLtiDeepLinkResponse() throws MalformedURLException, URISyntaxException {
createMockOidcIdToken();
when(tokenRetriever.createDeepLinkingJWT(anyString(), anyMap())).thenReturn(null);

Expand All @@ -95,7 +96,7 @@ void testEmptyJwtBuildLtiDeepLinkResponse() throws MalformedURLException {
}

@Test
void testEmptyReturnUrlBuildLtiDeepLinkResponse() throws JsonProcessingException, MalformedURLException {
void testEmptyReturnUrlBuildLtiDeepLinkResponse() throws JsonProcessingException, MalformedURLException, URISyntaxException {
createMockOidcIdToken();
when(tokenRetriever.createDeepLinkingJWT(anyString(), anyMap())).thenReturn("test_jwt");
ObjectMapper mapper = new ObjectMapper();
Expand Down Expand Up @@ -134,7 +135,7 @@ void testEmptyReturnUrlBuildLtiDeepLinkResponse() throws JsonProcessingException
}

@Test
void testEmptyDeploymentIdBuildLtiDeepLinkResponse() throws MalformedURLException {
void testEmptyDeploymentIdBuildLtiDeepLinkResponse() throws MalformedURLException, URISyntaxException {
createMockOidcIdToken();
when(tokenRetriever.createDeepLinkingJWT(anyString(), anyMap())).thenReturn("test_jwt");
when(oidcIdToken.getClaim(de.tum.in.www1.artemis.domain.lti.Claims.LTI_DEPLOYMENT_ID)).thenReturn(null);
Expand All @@ -145,7 +146,7 @@ void testEmptyDeploymentIdBuildLtiDeepLinkResponse() throws MalformedURLExceptio
.withMessage("Missing claim: " + Claims.LTI_DEPLOYMENT_ID);
}

private void createMockOidcIdToken() throws MalformedURLException {
private void createMockOidcIdToken() throws MalformedURLException, URISyntaxException {
Map<String, Object> mockSettings = new TreeMap<>();
mockSettings.put("deep_link_return_url", "test_return_url");
when(oidcIdToken.getClaim(Claims.DEEP_LINKING_SETTINGS)).thenReturn(mockSettings);
Expand All @@ -154,7 +155,7 @@ private void createMockOidcIdToken() throws MalformedURLException {
when(oidcIdToken.getClaim("exp")).thenReturn("12345");
when(oidcIdToken.getClaim("iat")).thenReturn("test");
when(oidcIdToken.getClaim("nonce")).thenReturn("1234-34535-abcbcbd");
when(oidcIdToken.getIssuer()).thenReturn(new URL("http://artemis.com"));
when(oidcIdToken.getIssuer()).thenReturn(new URI("http://artemis.com").toURL());
when(oidcIdToken.getAudience()).thenReturn(Arrays.asList("http://moodle.com"));
when(oidcIdToken.getExpiresAt()).thenReturn(Instant.now().plus(2, ChronoUnit.HOURS));
when(oidcIdToken.getIssuedAt()).thenReturn(Instant.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,8 @@ void testConsecutiveSaveFailsAfterAddingOrRemovingReferencedFeedback() throws Ex
verify(textBlockService, times(irrelevantCallCount + 3)).findAllBySubmissionId(textSubmission.getId());

Set<TextBlock> textBlocks = textBlockRepository.findAllBySubmissionId(textSubmissionWithoutAssessment.getId());
assertThat(textBlocks).allSatisfy(block -> assertThat(block).isEqualToComparingFieldByField(blocksSubmission.get(block.getId())));
final String[] ignoringFields = { "submission.results", "submission.submissionDate", "submission.participation", "submission.blocks", "submission.versions" };
assertThat(textBlocks).allSatisfy(block -> assertThat(block).usingRecursiveComparison().ignoringFields(ignoringFields).isEqualTo(blocksSubmission.get(block.getId())));
}

/**
Expand Down
Loading

0 comments on commit 7eed1c7

Please sign in to comment.