Skip to content

Commit

Permalink
Use XMLUnit for comparing XML. Make Octet strings hex uppercase to ma…
Browse files Browse the repository at this point in the history
…tch output of asn1c
  • Loading branch information
iyourshaw committed Feb 27, 2025
1 parent a2a7089 commit 72bb7ab
Show file tree
Hide file tree
Showing 53 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Asn1OctetString implements Asn1Type {

@JsonValue
public String getValue() {
HexFormat hexFormat = HexFormat.of();
HexFormat hexFormat = HexFormat.of().withUpperCase();
if (octets != null) {
return hexFormat.formatHex(octets);
} else {
Expand Down
2 changes: 2 additions & 0 deletions j2735-2024/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'
testImplementation 'org.hamcrest:hamcrest-library:2.2'
testImplementation 'commons-io:commons-io:2.18.0'
testImplementation 'org.xmlunit:xmlunit-core:2.10.0'
testImplementation 'org.xmlunit:xmlunit-matchers:2.10.0'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.xmlunit.matchers.CompareMatcher.isIdenticalTo;

public class BasicSafetyMessageTest extends BaseSerializeTest<BasicSafetyMessage> {

Expand All @@ -20,27 +21,45 @@ public BasicSafetyMessageTest() {
}

@ParameterizedTest
@MethodSource("getXmlResources")
public void xmlDeserializeTest(String resourcePath) throws IOException {
@MethodSource("getXmlResourcesNoExtensions")
public void canDeserializeXml_NoExtensionsTest(String resourcePath) throws IOException {
String xml = loadResource(resourcePath);
BasicSafetyMessage bsm = fromXml(xml);
assertThat(bsm, notNullValue());
}

@ParameterizedTest
@MethodSource("getJsonResources")
public void jsonDeserializeTest(String resourcePath) throws IOException {
@MethodSource("getXmlResourcesNoExtensions")
public void canRoundTripXml_NoExtensionsTest(String resourcePath) throws IOException {
String xml = loadResource(resourcePath);
BasicSafetyMessage bsm = fromXml(xml);
assertThat(bsm, notNullValue());
String roundTripXml = toXml(bsm);
assertThat(roundTripXml, isIdenticalTo(xml).ignoreComments().ignoreWhitespace());
}

@ParameterizedTest
@MethodSource("getJsonResourcesNoExtensions")
public void jsonDeserializeNoExtensionsTest(String resourcePath) throws IOException {
String json = loadResource(resourcePath);
BasicSafetyMessage bsm = fromJson(json);
assertThat(bsm, notNullValue());
}

private static Stream<Arguments> getXmlResources() {
return getResources("/BasicSafetyMessage/xml");
private static Stream<Arguments> getXmlResourcesNoExtensions() {
return getXmlResources("no_extensions");
}

private static Stream<Arguments> getJsonResourcesNoExtensions() {
return getJsonResources("no_extensions");
}

private static Stream<Arguments> getXmlResources(String subdirectory) {
return getResources("/BasicSafetyMessage/xml/" + subdirectory);
}

private static Stream<Arguments> getJsonResources() {
return getResources("/BasicSafetyMessage/json");
private static Stream<Arguments> getJsonResources(String subdirectory) {
return getResources("/BasicSafetyMessage/json/" + subdirectory);
}

private static Stream<Arguments> getResources(String directory) {
Expand Down

0 comments on commit 72bb7ab

Please sign in to comment.