Skip to content

Commit

Permalink
misc improvements, versioned 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jensdietrich committed Jun 15, 2020
1 parent ff7c0aa commit e0a66bc
Show file tree
Hide file tree
Showing 26 changed files with 126 additions and 62 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.5</version>
<version>1.0.6</version>
<name>yamf-parent</name>
<properties>
<project-version>1.0.5</project-version>
<project-version>1.0.6</project-version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
Expand Down Expand Up @@ -43,7 +43,7 @@
<module>yamf-acceptancetests</module>
<module>yamf-bytecodechecks</module>
<module>yamf-mvn</module>
<module>yamf-mswordreporting</module>
<module>yamf-msoffice-reporting</module>
</modules>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion yamf-acceptancetests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-acceptancetests</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ public class JUnitActions {
* @param junitRunner the junit runner library, for instance junit-platform-console-standalone-1.6.2.jar
* @param testClass the name of the class with tests
* @param classpath the classpath to be used
* @param includeJUnitReports whether to include the content of the generated junit report(s) in the test results
* @return test results
* @throws Exception
*/
public static TestResults test (File junitRunner,String testClass,String classpath,boolean includeJUnitReports) throws Exception {
public static TestResults test (File junitRunner, String testClass, String classpath, JUnitVersion junitVersion) throws Exception {

// see https://junit.org/junit5/docs/current/user-guide/ , section 4.3
Preconditions.checkArgument(junitRunner!=null,"JUnit runner library must be provided (junit-platform-console-standalone-1.6.2.jar or similar)");
Expand Down Expand Up @@ -66,19 +65,24 @@ public static TestResults test (File junitRunner,String testClass,String classpa

if (junitReportFolder.exists()) {
String details = "";
if (includeJUnitReports) {
for (File junitReport : junitReportFolder.listFiles(fl -> !fl.isHidden())) {
Attachments.add(new Attachment(junitReport.getName(),junitReport,"application/xml"));
try (Stream<String> stream = Files.lines(junitReport.toPath())) {
details = details + "======= " + junitReport.getName() + " =======\n";
details = details + stream.collect(Collectors.joining());
} catch (IOException e) {
throw new Exception(e);
for (File junitReport : junitReportFolder.listFiles(fl -> !fl.isHidden())) {
if (junitReport.getName().equals(JUPITER_REPORT_NAME)) {
if (junitVersion == JUnitVersion.JUNIT5) {
Attachments.add(new Attachment(junitReport.getName(),junitReport,"application/xml"));
}
}
}
else {
details = "junit reports were generated in " + junitReportFolder.getAbsolutePath();
else if (junitReport.getName().equals(VINTAGE_REPORT_NAME)) {
if (junitVersion == JUnitVersion.JUNIT4) {
Attachments.add(new Attachment(junitReport.getName(),junitReport,"application/xml"));
}
}

try (Stream<String> stream = Files.lines(junitReport.toPath())) {
details = details + "======= " + junitReport.getName() + " =======\n";
details = details + stream.collect(Collectors.joining());
} catch (IOException e) {
throw new Exception(e);
}
}
testResults.setDetails(details);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nz.ac.wgtn.yamf.checks.junit;

/**
* Supported JUnit versions.
* @author jens dietrich
*/
public enum JUnitVersion {
JUNIT4, JUNIT5
}
2 changes: 1 addition & 1 deletion yamf-bytecodechecks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-bytecodechecks</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion yamf-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nz.ac.wgtn.yamf;

import com.google.common.base.Preconditions;
import nz.ac.wgtn.yamf.reporting.msoffice.Reporter;
import nz.ac.wgtn.yamf.reporting.Reporter;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.DefaultConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testPlanExecutionStarted(TestPlan testPlan) {

@Override
public void testPlanExecutionFinished(TestPlan testPlan) {
System.out.println("Tests finished");
LOGGER.info("Tests finished");
Attachments.reset();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nz.ac.wgtn.yamf.reporting.msoffice;
package nz.ac.wgtn.yamf.reporting;

import nz.ac.wgtn.yamf.MarkingResultRecord;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nz.ac.wgtn.yamf.reporting.msoffice;
package nz.ac.wgtn.yamf.reporting;

import nz.ac.wgtn.yamf.MarkingResultRecord;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nz.ac.wgtn.yamf.reporting.msoffice;
package nz.ac.wgtn.yamf.reporting;

import nz.ac.wgtn.yamf.MarkingResultRecord;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nz.ac.wgtn.yamf.reporting.msoffice;
package nz.ac.wgtn.yamf.reporting;

import nz.ac.wgtn.yamf.MarkingResultRecord;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nz.ac.wgtn.yamf.reporting.msoffice;
package nz.ac.wgtn.yamf.reporting;

import java.util.function.Predicate;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nz.ac.vuw.jenz</groupId>
<artifactId>jmkr-mvn-example2-submission1</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>jmkr-mvn-example2-acceptancetests</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package assignment;

/**
* Some sample class to show testing.
* The brief is to implement standard addition, but to throw an IllegalArgumentException if an overflow occurs.
* @author jens dietrich
*/
public class Calculator {

public static int safelyAdd (int x, int y) {
int s = x + y;
if (s < Math.max(x,y)) {
throw new IllegalArgumentException();
}
else {
return s;
}
}
}
2 changes: 1 addition & 1 deletion yamf-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-examples</artifactId>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified yamf-examples/sample-reports/example-mvn-marks-submission1.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import nz.ac.wgtn.yamf.Attachment;
import nz.ac.wgtn.yamf.Attachments;
import nz.ac.wgtn.yamf.checks.junit.JUnitActions;
import nz.ac.wgtn.yamf.checks.junit.JUnitVersion;
import nz.ac.wgtn.yamf.checks.junit.TestResults;
import nz.ac.wgtn.yamf.checks.mvn.MVNActions;
import nz.ac.wgtn.yamf.Marking;
Expand Down Expand Up @@ -39,15 +40,15 @@ public static void prepareAcceptanceTests () throws Exception {
@Test
@Marking(name="Q1 -- run simple acceptance tests",marks=5.0)
public void runSimpleAcceptanceTests () throws Exception {
TestResults results = MVNActions.acceptanceTestMvnProject(junitRunner,"acceptancetests.TestCalculatorSimple", submission,acceptanceTestProjectFolder,true,true);
TestResults results = MVNActions.acceptanceTestMvnProject(junitRunner,"acceptancetests.TestCalculatorSimple", submission,acceptanceTestProjectFolder,true, JUnitVersion.JUNIT5);
Assumptions.assumeTrue(results.getTests() == 3);
Assertions.assertSame(3,results.getTestsSuccessed(),"not all tests succeeded, details:\n" + results.getDetails());
}

@Test
@Marking(name="Q2 -- run advanced acceptance tests to check overflow handing",marks=5.0)
public void runAdvancedAcceptanceTests () throws Exception {
TestResults results = MVNActions.acceptanceTestMvnProject(junitRunner,"acceptancetests.TestCalculatorOverflow", submission,acceptanceTestProjectFolder,true,true);
TestResults results = MVNActions.acceptanceTestMvnProject(junitRunner,"acceptancetests.TestCalculatorOverflow", submission,acceptanceTestProjectFolder,true,JUnitVersion.JUNIT5);
Assumptions.assumeTrue(results.getTests() == 1);
Assertions.assertSame(1,results.getTestsSuccessed(),"not all tests succeeded, details:\n" + results.getDetails());
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-mswordreporting</artifactId>
<artifactId>yamf-msoffice-reporting</artifactId>
<packaging>jar</packaging>
<version>${project-version}</version>
<name>yamf-mswordreporting</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import com.google.common.io.Files;
import nz.ac.wgtn.yamf.Attachment;
import nz.ac.wgtn.yamf.MarkingResultRecord;
import nz.ac.wgtn.yamf.reporting.Reporter;
import nz.ac.wgtn.yamf.reporting.StackTraceFilters;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
Expand Down Expand Up @@ -48,22 +49,6 @@ public MSExcelReporter(String fileName) {
this(false,fileName);
}

public boolean isReportFailureAndErrorDetails() {
return reportFailureAndErrorDetails;
}

public void setReportFailureAndErrorDetails(boolean reportFailureAndErrorDetails) {
this.reportFailureAndErrorDetails = reportFailureAndErrorDetails;
}

public Predicate<StackTraceElement> getStacktraceElementFilter() {
return stacktraceElementFilter;
}

public void setStacktraceElementFilter(Predicate<StackTraceElement> stacktraceElementFilter) {
this.stacktraceElementFilter = stacktraceElementFilter;
}

@Override
public void generateReport(List<MarkingResultRecord> markingResultRecords) {

Expand Down Expand Up @@ -98,7 +83,16 @@ public void generateReport(List<MarkingResultRecord> markingResultRecords) {

addCell(row,col++,styleR,record.getMark());
addCell(row,col++,styleR,record.getMaxMark());
addCell(row,col++,styleL,record.getManualMarkingInstructions());

String notes = "";
if (record.isManualMarkingRequired()) {
notes = record.getManualMarkingInstructions();
}
else if (record.isAborted() && record.getThrowable()!=null) {
notes = record.getThrowable().getMessage();
}

addCell(row,col++,styleL,notes);

Collection<Attachment>attachmentsOfThisRecord = record.getAttachments();
List<String> attachmentNames = new ArrayList<>();
Expand Down Expand Up @@ -126,7 +120,11 @@ public void generateReport(List<MarkingResultRecord> markingResultRecords) {
cell.setCellFormula(formula ); // =SUM(C2:C3)
cell.setCellStyle(styleR);

addCell(row,col++,styleC,"");
cell = row.createCell(col++);
formula = IntStream.range(2,rowCount).mapToObj(i -> "D"+i).collect(Collectors.joining("+"));
cell.setCellFormula(formula ); // =SUM(C2:C3)
cell.setCellStyle(styleR);

addCell(row,col++,styleC,"");
addCell(row,col++,styleC,"");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nz.ac.wgtn.yamf.reporting.msoffice;

import nz.ac.wgtn.yamf.MarkingResultRecord;
import nz.ac.wgtn.yamf.reporting.Reporter;
import nz.ac.wgtn.yamf.reporting.StackTraceFilters;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
Expand Down
2 changes: 1 addition & 1 deletion yamf-mvn/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<groupId>nz.ac.wgtn.yamf</groupId>
<artifactId>yamf-mvn</artifactId>
Expand Down
Loading

0 comments on commit e0a66bc

Please sign in to comment.