From 510e57d905edc56d64b1089dd2dd347bf9e2e675 Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Tue, 1 Aug 2023 14:20:51 +0200 Subject: [PATCH] test: add more tests to verify deserialisation (#39) --- watchdog-agent/src/test/java/OptionsTest.java | 26 ++++++++++++++++--- .../src/test/resources/fingerprints/jar.jsonl | 7 +++++ .../resources/fingerprints/maven_jar.jsonl | 6 +++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 watchdog-agent/src/test/resources/fingerprints/jar.jsonl create mode 100644 watchdog-agent/src/test/resources/fingerprints/maven_jar.jsonl diff --git a/watchdog-agent/src/test/java/OptionsTest.java b/watchdog-agent/src/test/java/OptionsTest.java index fd29262f..3919243c 100644 --- a/watchdog-agent/src/test/java/OptionsTest.java +++ b/watchdog-agent/src/test/java/OptionsTest.java @@ -2,6 +2,7 @@ import io.github.algomaster99.Options; import io.github.algomaster99.terminator.commons.fingerprint.Fingerprint; +import io.github.algomaster99.terminator.commons.fingerprint.Jar; import io.github.algomaster99.terminator.commons.fingerprint.Maven; import java.io.File; import java.lang.reflect.InvocationTargetException; @@ -15,12 +16,29 @@ public class OptionsTest { class ParseFingerprint { @Test void maven() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + List fingerprints = deserializeFingerprints("src/test/resources/fingerprints/maven.jsonl"); + assertThat(fingerprints).hasOnlyElementsOfType(Maven.class).size().isEqualTo(2); + } + + @Test + void jar() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + List fingerprints = deserializeFingerprints("src/test/resources/fingerprints/jar.jsonl"); + assertThat(fingerprints).hasOnlyElementsOfType(Jar.class).size().isEqualTo(7); + } + + @Test + void maven_jar() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + List fingerprints = deserializeFingerprints("src/test/resources/fingerprints/maven_jar.jsonl"); + assertThat(fingerprints).elements(0, 2).hasOnlyElementsOfType(Maven.class); + assertThat(fingerprints).elements(3, 5).hasOnlyElementsOfType(Jar.class); + } + + private List deserializeFingerprints(String pathname) + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Method method = Options.class.getDeclaredMethod("parseFingerprints", File.class); method.setAccessible(true); - Object result = method.invoke(null, new File("src/test/resources/fingerprints/maven.jsonl")); - - List fingerprints = (List) result; - assertThat(fingerprints).hasOnlyElementsOfType(Maven.class).size().isEqualTo(2); + Object result = method.invoke(null, new File(pathname)); + return (List) result; } } } diff --git a/watchdog-agent/src/test/resources/fingerprints/jar.jsonl b/watchdog-agent/src/test/resources/fingerprints/jar.jsonl new file mode 100644 index 00000000..18efd71c --- /dev/null +++ b/watchdog-agent/src/test/resources/fingerprints/jar.jsonl @@ -0,0 +1,7 @@ +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/Java","classFileVersion":"55.0","hash":"b5ffd375494a8a018285fdd6532aecbfd2be757b2347fe58d38b6ef486dea941","algorithm":"SHA256"} +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/DroppedPropertiesSensor","classFileVersion":"55.0","hash":"343e442953f0222644ce6aa3ce46649da747022fa0176c6b0a2ee153589cbb6a","algorithm":"SHA256"} +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/api/package-info","classFileVersion":"55.0","hash":"e072966b9c3e77b06678b56e61f040e1b54bf5d8615a4cff183e014c4aa60492","algorithm":"SHA256"} +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/data/UnitTestClassReport","classFileVersion":"55.0","hash":"a058963df7e50c2b0e9244c5dca4da4871819d2e41b3fa9572fb68d5d42cd5fe","algorithm":"SHA256"} +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/data/UnitTestResult","classFileVersion":"55.0","hash":"22869f19e555e562afc53bba32fe528df1d668505545b00ce4377ec2021a857b","algorithm":"SHA256"} +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/data/UnitTestIndex","classFileVersion":"55.0","hash":"bf8e6c60a7ee628711a9c4f6580aba31c8a151be0d9550c46f632a374d4669d0","algorithm":"SHA256"} +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/SurefireJavaParser","classFileVersion":"55.0","hash":"254f59d4f9b67da425af0ab13572da31a9d3201f3313795cbd1c2c716a3b0ebf","algorithm":"SHA256"} \ No newline at end of file diff --git a/watchdog-agent/src/test/resources/fingerprints/maven_jar.jsonl b/watchdog-agent/src/test/resources/fingerprints/maven_jar.jsonl new file mode 100644 index 00000000..bcc3abe1 --- /dev/null +++ b/watchdog-agent/src/test/resources/fingerprints/maven_jar.jsonl @@ -0,0 +1,6 @@ +{"groupId":"com.google.j2objc","artifactId":"j2objc-annotations","version":"2.8","className":"com/google/j2objc/annotations/WeakOuter","classFileVersion":"51.0","hash":"7762fe98c21931d5ca5ed99d574cfcef2aa430863ac74258a40955cf0a215d50","algorithm":"SHA256"} +{"groupId":"com.google.j2objc","artifactId":"j2objc-annotations","version":"2.8","className":"com/google/j2objc/annotations/LoopTranslation$LoopStyle","classFileVersion":"51.0","hash":"9ff5c8ce518e62b544dac56a0a51b62e44f03d1907519da4b3344d5ab709a2c4","algorithm":"SHA256"} +{"groupId":"com.google.j2objc","artifactId":"j2objc-annotations","version":"2.8","className":"com/google/j2objc/annotations/J2ObjCIncompatible","classFileVersion":"51.0","hash":"ca2dd3ff4f3e025414279ee7102bfdbe04c7b035b1d9adf62180b19b91f285ad","algorithm":"SHA256"} +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/package-info","classFileVersion":"55.0","hash":"3e844019225a05bf7bbced91024d3780a3c39d375c4eaeee22f1adb68d156ecd","algorithm":"SHA256"} +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/JavaSonarWayProfile","classFileVersion":"55.0","hash":"d235f7ac1c020656dcfc91d9688ffe9160b145a1cf2c6d235152d7fc48a4f06f","algorithm":"SHA256"} +{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/JavaPlugin","classFileVersion":"55.0","hash":"f15bf5c696718a521b9234bf893dbb50b10e10fa0a6201d2ec09c0ec92c4f81d","algorithm":"SHA256"} \ No newline at end of file