Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions json-compatibility-suite/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.github.simbo1905.json</groupId>
<artifactId>json-java21-parent</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>

<artifactId>json-compatibility-suite</artifactId>
<packaging>jar</packaging>

<name>JSON Compatibility Suite</name>

<dependencies>
<dependency>
<groupId>io.github.simbo1905.json</groupId>
<artifactId>json-java21</artifactId>
<version>${project.version}</version>
</dependency>
<!-- JUnit 5 for testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<executions>
<execution>
<id>download-json-test-suite</id>
<phase>generate-test-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/nst/JSONTestSuite/archive/refs/heads/master.zip</url>
<outputDirectory>${project.build.directory}/test-resources</outputDirectory>
<outputFileName>json-test-suite.zip</outputFileName>
<unpack>true</unpack>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package jdk.sandbox.compatibility;

import org.junit.jupiter.api.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.assertj.core.api.Assertions.assertThat;

public class DownloadVerificationTest {
@Test
void testSuiteDownloaded() {
Path testDir = Paths.get("target/test-resources/JSONTestSuite-master/test_parsing");
assertThat(testDir)
.as("JSON Test Suite should be downloaded and extracted")
.exists()
.isDirectory();

// Verify some test files exist
assertThat(testDir.resolve("y_structure_whitespace_array.json"))
.as("Should contain valid test files")
.exists();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package jdk.sandbox.compatibility;

import jdk.sandbox.java.util.json.Json;
import jdk.sandbox.java.util.json.JsonParseException;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.*;

/**
* Runs the JSON Test Suite against our implementation.
* Files are categorized:
* - y_*.json: Valid JSON that MUST parse successfully
* - n_*.json: Invalid JSON that MUST fail to parse
* - i_*.json: Implementation-defined (may accept or reject)
*/
public class JsonTestSuiteTest {

private static final Path TEST_DIR = Paths.get("target/test-resources/JSONTestSuite-master/test_parsing");

@TestFactory
Stream<DynamicTest> runJsonTestSuite() throws Exception {
if (!Files.exists(TEST_DIR)) {
System.err.println("Test suite not found. Run: mvn test-compile");
return Stream.empty();
}

return Files.walk(TEST_DIR)
.filter(p -> p.toString().endsWith(".json"))
.sorted()
.map(this::createTest);
}

private DynamicTest createTest(Path file) {
String filename = file.getFileName().toString();

return DynamicTest.dynamicTest(filename, () -> {
String content = Files.readString(file);

if (filename.startsWith("y_")) {
// Valid JSON - must parse successfully
assertThatCode(() -> Json.parse(content))
.as("File %s should parse successfully", filename)
.doesNotThrowAnyException();

} else if (filename.startsWith("n_")) {
// Invalid JSON - must fail to parse
assertThatThrownBy(() -> Json.parse(content))
.as("File %s should fail to parse", filename)
.isInstanceOf(JsonParseException.class);

} else if (filename.startsWith("i_")) {
// Implementation defined - just verify no crash
try {
Json.parse(content);
// OK - we accepted it
} catch (JsonParseException e) {
// OK - we rejected it
} catch (Exception e) {
// NOT OK - unexpected exception type
fail("Unexpected exception for %s: %s", filename, e);
}
}
});
}
}
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<modules>
<module>json-java21</module>
<module>json-java21-api-tracker</module>
<module>json-compatibility-suite</module>
</modules>

<properties>
Expand All @@ -53,6 +54,7 @@
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
<maven-install-plugin.version>3.1.2</maven-install-plugin.version>
<download-maven-plugin.version>1.7.1</download-maven-plugin.version>
</properties>


Expand Down Expand Up @@ -113,7 +115,12 @@
<artifactId>maven-install-plugin</artifactId>
<version>${maven-install-plugin.version}</version>
</plugin>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>${download-maven-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
</project>
Loading