|
21 | 21 | import static net.javacrumbs.jsonunit.JsonAssert.assertJsonNodePresent; |
22 | 22 | import static net.javacrumbs.jsonunit.JsonAssert.assertJsonPartEquals; |
23 | 23 | import static net.javacrumbs.jsonunit.JsonAssert.whenIgnoringPaths; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
24 | 25 |
|
25 | 26 | import java.io.File; |
26 | 27 | import java.io.IOException; |
|
33 | 34 | import java.time.Instant; |
34 | 35 | import java.util.Collections; |
35 | 36 | import java.util.Date; |
| 37 | +import java.util.Iterator; |
36 | 38 | import java.util.Properties; |
| 39 | +import java.util.Set; |
| 40 | +import java.util.TreeSet; |
37 | 41 |
|
38 | 42 | import com.fasterxml.jackson.databind.JsonNode; |
39 | 43 | import com.fasterxml.jackson.databind.ObjectMapper; |
@@ -173,14 +177,31 @@ private static void assertStatementContent(final JsonNode statement) { |
173 | 177 | JsonAssert.when(Option.IGNORING_VALUES).whenIgnoringPaths("jvm.args", "env")); |
174 | 178 | assertJsonEquals(expectedStatement.at("/predicate/buildDefinition/internalParameters"), |
175 | 179 | statement.at("/predicate/buildDefinition/internalParameters")); |
| 180 | + // `[0].annotations` holds JVM system properties; |
| 181 | + // Not all properties are available on all JDKs, so they are either null or strings, which json-unit treats as a structural mismatch. |
| 182 | + // We will check them below |
176 | 183 | assertJsonEquals(expectedStatement.at("/predicate/buildDefinition/resolvedDependencies"), |
177 | 184 | statement.at("/predicate/buildDefinition/resolvedDependencies"), |
178 | | - JsonAssert.when(Option.IGNORING_VALUES)); |
| 185 | + JsonAssert.when(Option.IGNORING_VALUES).whenIgnoringPaths("[0].annotations")); |
| 186 | + Set<String> expectedJdkFields = fieldNames( |
| 187 | + expectedStatement.at("/predicate/buildDefinition/resolvedDependencies/0/annotations")); |
| 188 | + Set<String> actualJdkFields = fieldNames( |
| 189 | + statement.at("/predicate/buildDefinition/resolvedDependencies/0/annotations")); |
| 190 | + assertEquals(expectedJdkFields, actualJdkFields); |
179 | 191 | assertJsonEquals(expectedStatement.at("/predicate/runDetails"), |
180 | 192 | statement.at("/predicate/runDetails"), |
181 | 193 | whenIgnoringPaths("metadata.finishedOn")); |
182 | 194 | } |
183 | 195 |
|
| 196 | + private static Set<String> fieldNames(final JsonNode node) { |
| 197 | + Set<String> names = new TreeSet<>(); |
| 198 | + Iterator<String> it = node.fieldNames(); |
| 199 | + while (it.hasNext()) { |
| 200 | + names.add(it.next()); |
| 201 | + } |
| 202 | + return names; |
| 203 | + } |
| 204 | + |
184 | 205 | @Test |
185 | 206 | void attestationTest() throws Exception { |
186 | 207 | MavenProjectHelper projectHelper = container.lookup(MavenProjectHelper.class); |
|
0 commit comments