-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated code lifecycle: Add Java blackbox exercise template (#10118)
- Loading branch information
1 parent
445920e
commit 5babeab
Showing
12 changed files
with
443 additions
and
160 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/main/java/de/tum/cit/aet/artemis/buildagent/dto/CustomFeedback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.tum.cit.aet.artemis.buildagent.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record CustomFeedback(@JsonProperty("name") String name, @JsonProperty("successful") boolean successful, @JsonProperty("message") String message) { | ||
|
||
public String getMessage() { | ||
return message != null ? message : ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/de/tum/cit/aet/artemis/buildagent/service/parser/CustomFeedbackParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package de.tum.cit.aet.artemis.buildagent.service.parser; | ||
|
||
import java.io.IOException; | ||
import java.util.InvalidPropertiesFormatException; | ||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import de.tum.cit.aet.artemis.buildagent.dto.CustomFeedback; | ||
import de.tum.cit.aet.artemis.buildagent.dto.LocalCITestJobDTO; | ||
|
||
public final class CustomFeedbackParser { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(CustomFeedbackParser.class); | ||
|
||
private static final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
private CustomFeedbackParser() { | ||
|
||
} | ||
|
||
/** | ||
* Parses the test result file and extracts failed and successful tests. | ||
* | ||
* @param fileName The name of the result file. Needs to be present. | ||
* @param testResultFileString The content of the test result file as a String. | ||
* @param failedTests A list of failed tests. This list will be populated by the method. | ||
* @param successfulTests A list of successful tests. This list will be populated by the method. | ||
*/ | ||
public static void processTestResultFile(final String fileName, final String testResultFileString, final List<LocalCITestJobDTO> failedTests, | ||
final List<LocalCITestJobDTO> successfulTests) { | ||
final CustomFeedback feedback; | ||
try { | ||
feedback = mapper.readValue(testResultFileString, CustomFeedback.class); | ||
validateCustomFeedback(fileName, feedback); | ||
} | ||
catch (IOException e) { | ||
log.error("Error during custom Feedback creation. {}", e.getMessage(), e); | ||
return; | ||
} | ||
List<LocalCITestJobDTO> toAddFeedbackTo = feedback.successful() ? successfulTests : failedTests; | ||
toAddFeedbackTo.add(new LocalCITestJobDTO(feedback.name(), List.of(feedback.getMessage()))); | ||
} | ||
|
||
/** | ||
* Checks that the custom feedback has a valid format | ||
* <p> | ||
* A custom feedback has to have a non-empty, non only-whitespace name to be able to identify it in Artemis. | ||
* If it is not successful, there has to be a message explaining a reason why this is the case. | ||
* | ||
* @param fileName where the custom feedback was read from. | ||
* @param feedback the custom feedback to validate. | ||
* @throws InvalidPropertiesFormatException if one of the invariants described above does not hold. | ||
*/ | ||
private static void validateCustomFeedback(final String fileName, final CustomFeedback feedback) throws InvalidPropertiesFormatException { | ||
if (feedback.name() == null || feedback.name().trim().isEmpty()) { | ||
throw new InvalidPropertiesFormatException(String.format("Custom feedback from file %s needs to have a name attribute.", fileName)); | ||
} | ||
if (!feedback.successful() && (feedback.message() == null || feedback.message().trim().isEmpty())) { | ||
throw new InvalidPropertiesFormatException(String.format("Custom non-success feedback from file %s needs to have a message", fileName)); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ildagent/service/TestResultXmlParser.java → ...t/service/parser/TestResultXmlParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.