From 3809cf8dd39620044d0be84ee53c44ba3a77eb11 Mon Sep 17 00:00:00 2001 From: cxcorp Date: Wed, 30 Nov 2016 01:00:48 +0200 Subject: [PATCH 1/5] Fix deserialization of Files in ValidationResultsImpl --- .../serialization/SubmissionResultParser.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java b/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java index c252c844..1817bd9d 100644 --- a/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java +++ b/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java @@ -5,7 +5,6 @@ import fi.helsinki.cs.tmc.testrunner.CaughtException; import fi.helsinki.cs.tmc.testrunner.StackTraceSerializer; -import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.reflect.TypeParameter; import com.google.common.reflect.TypeToken; @@ -21,6 +20,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.io.IOException; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -49,6 +49,11 @@ SubmissionResult.Status.class, new StatusDeserializer()) StackTraceElement.class, new StackTraceSerializer()) .registerTypeAdapter( ImmutableList.class, new ImmutableListJsonDeserializer()) + .registerTypeAdapter( + /* Needed because ValidationResultImpl stores filenames in + * Map, but Gson doesn't know + * how to deserialize a string into a File */ + File.class, new FileDeserializer()) .create(); SubmissionResult result = gson.fromJson(json, SubmissionResult.class); @@ -91,7 +96,17 @@ public SubmissionResult.Status deserialize( } } - private class ImmutableListJsonDeserializer implements JsonDeserializer> { + private static class FileDeserializer implements JsonDeserializer { + @Override + public File deserialize( + JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) + throws JsonParseException { + String filePath = jsonElement.getAsString(); + return new File(filePath); + } + } + + private static class ImmutableListJsonDeserializer implements JsonDeserializer> { @Override public ImmutableList deserialize( JsonElement json, Type type, JsonDeserializationContext context) From 7a94b20d709e60aebe48af7340321741b6eeb207 Mon Sep 17 00:00:00 2001 From: cxcorp Date: Wed, 30 Nov 2016 01:03:53 +0200 Subject: [PATCH 2/5] Fix deserialization error caused by ValidationError having no public ctor --- .../serialization/SubmissionResultParser.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java b/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java index 1817bd9d..87f3799f 100644 --- a/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java +++ b/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java @@ -1,6 +1,8 @@ package fi.helsinki.cs.tmc.core.communication.serialization; import fi.helsinki.cs.tmc.core.domain.submission.SubmissionResult; +import fi.helsinki.cs.tmc.core.domain.submission.ValidationErrorImpl; +import fi.helsinki.cs.tmc.langs.abstraction.ValidationError; import fi.helsinki.cs.tmc.stylerunner.validation.CheckstyleResult; import fi.helsinki.cs.tmc.testrunner.CaughtException; import fi.helsinki.cs.tmc.testrunner.StackTraceSerializer; @@ -10,6 +12,7 @@ import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.InstanceCreator; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; @@ -54,6 +57,11 @@ ImmutableList.class, new ImmutableListJsonDeserializer()) * Map, but Gson doesn't know * how to deserialize a string into a File */ File.class, new FileDeserializer()) + .registerTypeAdapter( + /* Needed because ValidationResultImpl stores errors in + * abstract ValidationErrors which obviously don't have a + * default constructor for Gson to use */ + ValidationError.class, new ValidationErrorInstanceCreator()) .create(); SubmissionResult result = gson.fromJson(json, SubmissionResult.class); @@ -96,6 +104,13 @@ public SubmissionResult.Status deserialize( } } + private static class ValidationErrorInstanceCreator implements InstanceCreator { + @Override + public ValidationError createInstance(Type type) { + return new ValidationErrorImpl(); + } + } + private static class FileDeserializer implements JsonDeserializer { @Override public File deserialize( From ff3e6fdbb6a2e0315292a78d0b7923258b435ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joona=20Heikkil=C3=A4?= Date: Thu, 1 Dec 2016 16:41:32 +0200 Subject: [PATCH 3/5] Add SubmissionResultParser test case for failed checkstyle Also cleaned checkstyle violations from tests and parser --- .../serialization/SubmissionResultParser.java | 8 ++-- .../SubmissionResultParserTest.java | 40 ++++++++++++++----- src/test/resources/json/checkstyleFailed.json | 4 +- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java b/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java index 87f3799f..5e7eca1b 100644 --- a/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java +++ b/src/main/java/fi/helsinki/cs/tmc/core/communication/serialization/SubmissionResultParser.java @@ -104,7 +104,8 @@ public SubmissionResult.Status deserialize( } } - private static class ValidationErrorInstanceCreator implements InstanceCreator { + private static class ValidationErrorInstanceCreator + implements InstanceCreator { @Override public ValidationError createInstance(Type type) { return new ValidationErrorImpl(); @@ -114,14 +115,15 @@ public ValidationError createInstance(Type type) { private static class FileDeserializer implements JsonDeserializer { @Override public File deserialize( - JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) + JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { String filePath = jsonElement.getAsString(); return new File(filePath); } } - private static class ImmutableListJsonDeserializer implements JsonDeserializer> { + private static class ImmutableListJsonDeserializer + implements JsonDeserializer> { @Override public ImmutableList deserialize( JsonElement json, Type type, JsonDeserializationContext context) diff --git a/src/test/java/fi/helsinki/cs/tmc/core/communication/http/serialization/SubmissionResultParserTest.java b/src/test/java/fi/helsinki/cs/tmc/core/communication/http/serialization/SubmissionResultParserTest.java index 9ab0f1de..f62ef2e0 100644 --- a/src/test/java/fi/helsinki/cs/tmc/core/communication/http/serialization/SubmissionResultParserTest.java +++ b/src/test/java/fi/helsinki/cs/tmc/core/communication/http/serialization/SubmissionResultParserTest.java @@ -5,24 +5,22 @@ import fi.helsinki.cs.tmc.core.communication.serialization.SubmissionResultParser; import fi.helsinki.cs.tmc.core.domain.submission.SubmissionResult; import fi.helsinki.cs.tmc.core.utils.TestUtils; +import fi.helsinki.cs.tmc.langs.abstraction.Strategy; +import fi.helsinki.cs.tmc.langs.abstraction.ValidationError; +import fi.helsinki.cs.tmc.langs.abstraction.ValidationResult; import fi.helsinki.cs.tmc.langs.domain.TestResult; -import fi.helsinki.cs.tmc.testrunner.TestCase; import com.google.common.collect.ImmutableList; -import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.net.URI; +import java.io.File; +import java.io.IOException; import java.util.List; +import java.util.Map; public class SubmissionResultParserTest { - private SubmissionResultParser parser; @Before @@ -39,7 +37,7 @@ public void parsesNonLangsTestResult() throws Exception { TestResult test = tests.get(0); assertThat(test.getException()).isInstanceOf(ImmutableList.class); assertThat(test.getException().size()).isEqualTo(27); - for (String str : test.getException()){ + for (String str : test.getException()) { assertThat(str).isInstanceOf(String.class); } } @@ -54,8 +52,30 @@ public void parsesLangsTestResult() throws Exception { TestResult test = tests.get(0); assertThat(test.getDetailedMessage()).isInstanceOf(ImmutableList.class); assertThat(test.getDetailedMessage().size()).isEqualTo(26); - for (String str : test.getDetailedMessage()){ + for (String str : test.getDetailedMessage()) { assertThat(str).isInstanceOf(String.class); } } + + @Test + public void parsesTestResultsWithFailedCheckstyle() throws IOException { + String json = TestUtils.readJsonFile(this.getClass(), "checkstyleFailed.json"); + SubmissionResult submissionResult = parser.parseFromJson(json); + assertThat(submissionResult).isNotNull(); + + ValidationResult result = submissionResult.getValidationResult(); + assertThat(result.getStrategy()).isEqualTo(Strategy.FAIL); + + Map> filesErrors = result.getValidationErrors(); + assertThat(filesErrors).hasSize(1); + + List errors = filesErrors.get(new File("error/errorMessages.java")); + assertThat(errors).hasSize(73); + + for (ValidationError error : errors) { + assertThat(error).isNotNull(); + assertThat(error.getMessage()).isNotNull(); + assertThat(error.getSourceName()).isNotNull(); + } + } } diff --git a/src/test/resources/json/checkstyleFailed.json b/src/test/resources/json/checkstyleFailed.json index f5d41903..137810cc 100644 --- a/src/test/resources/json/checkstyleFailed.json +++ b/src/test/resources/json/checkstyleFailed.json @@ -205,7 +205,7 @@ "strategy": "FAIL", "validationErrors": { - "eRror/errorMessages.java": + "error/errorMessages.java": [ { "column": 0, @@ -725,4 +725,4 @@ "requests_review": false, "submitted_at": "2015-06-04T13:34:58.155+03:00" -} \ No newline at end of file +} From 426609c97c9b54e181a4e417170f7bb8117e5bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joona=20Heikkil=C3=A4?= Date: Thu, 1 Dec 2016 16:53:27 +0200 Subject: [PATCH 4/5] Bump version to 0.9.3-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fd873d3e..a92226ea 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ fi.helsinki.cs.tmc core - 0.9.2-SNAPSHOT + 0.9.3-SNAPSHOT jar tmc-core http://testmycode.net From 63255a3d26db667d862250ef9426e07bdc6cddca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joona=20Heikkil=C3=A4?= Date: Thu, 1 Dec 2016 17:17:29 +0200 Subject: [PATCH 5/5] Remove unused SubmissionResult.validations in favor of validationResult --- .../tmc/core/domain/submission/SubmissionResult.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/fi/helsinki/cs/tmc/core/domain/submission/SubmissionResult.java b/src/main/java/fi/helsinki/cs/tmc/core/domain/submission/SubmissionResult.java index 12113083..b6ea4c25 100644 --- a/src/main/java/fi/helsinki/cs/tmc/core/domain/submission/SubmissionResult.java +++ b/src/main/java/fi/helsinki/cs/tmc/core/domain/submission/SubmissionResult.java @@ -75,8 +75,6 @@ public SubmissionResult() { @SerializedName("solution_url") private String solutionUrl; - private ValidationResultImpl validations; - private String valgrind; private boolean reviewed; @@ -105,14 +103,6 @@ public void setError(String error) { this.error = error; } - public ValidationResultImpl getValidations() { - return validations; - } - - public void setValidations(ValidationResultImpl validations) { - this.validations = validations; - } - public List getTestCases() { return testCases; } @@ -322,8 +312,6 @@ public String toString() { + feedbackAnswerUrl + ", solutionUrl=" + solutionUrl - + ", validations=" - + validations + ", \n valgrind=" + valgrind + ", reviewed="