-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
758 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...anomalydetection/src/test/java/ec/nbdemetra/anomalydetection/RuntimeDependenciesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package ec.nbdemetra.anomalydetection; | ||
|
||
import ec.nbdemetra.core.NbmMavenClassPath; | ||
import nbbrd.io.FileParser; | ||
import org.assertj.core.api.Condition; | ||
import org.assertj.core.api.ListAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.jar.Manifest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class RuntimeDependenciesTest { | ||
|
||
@Test | ||
public void test() throws IOException { | ||
assertThat(getRuntimeDependencies()) | ||
.describedAs("Check runtime dependencies") | ||
.satisfies(RuntimeDependenciesTest::checkNoDemetra) | ||
.satisfies(RuntimeDependenciesTest::checkNoJavaIoUtil) | ||
.satisfies(RuntimeDependenciesTest::checkNoSlf4j) | ||
.satisfies(RuntimeDependenciesTest::checkNoGuava) | ||
.isEmpty(); | ||
} | ||
|
||
private static void checkNoGuava(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.google.guava").isEmpty(); | ||
} | ||
|
||
private static void checkNoSlf4j(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "org.slf4j").isEmpty(); | ||
} | ||
|
||
private static void checkNoJavaIoUtil(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.github.nbbrd.java-io-util").isEmpty(); | ||
} | ||
|
||
private static void checkNoDemetra(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "eu.europa.ec.joinup.sat").isEmpty(); | ||
} | ||
|
||
private static ListAssert<? extends NbmMavenClassPath.GAV> assertThatGroupId(List<? extends NbmMavenClassPath.GAV> coordinates, String groupId) { | ||
return assertThat(coordinates) | ||
.describedAs("Check " + groupId) | ||
.filteredOn(NbmMavenClassPath.GAV::getGroupId, groupId); | ||
} | ||
|
||
private static Condition<List<? extends NbmMavenClassPath.GAV>> sameVersion() { | ||
return new Condition<>(NbmMavenClassPath.GAV::haveSameVersion, "same version"); | ||
} | ||
|
||
private static List<NbmMavenClassPath.GAV> getRuntimeDependencies() throws IOException { | ||
return FileParser.onParsingStream(Manifest::new) | ||
.andThen(NbmMavenClassPath::parse) | ||
.parseResource(RuntimeDependenciesTest.class, "/runtime-dependencies.mf"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
nbdemetra-common/src/test/java/ec/nbdemetra/common/RuntimeDependenciesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ec.nbdemetra.common; | ||
|
||
import ec.nbdemetra.core.NbmMavenClassPath; | ||
import nbbrd.io.FileParser; | ||
import org.assertj.core.api.Condition; | ||
import org.assertj.core.api.ListAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.jar.Manifest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class RuntimeDependenciesTest { | ||
|
||
@Test | ||
public void test() throws IOException { | ||
assertThat(getRuntimeDependencies()) | ||
.describedAs("Check runtime dependencies") | ||
.satisfies(RuntimeDependenciesTest::checkDemetra) | ||
.satisfies(RuntimeDependenciesTest::checkNoJavaIoUtil) | ||
.satisfies(RuntimeDependenciesTest::checkNoSlf4j) | ||
.satisfies(RuntimeDependenciesTest::checkNoGuava) | ||
.hasSize(2); | ||
} | ||
|
||
private static void checkNoGuava(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.google.guava").isEmpty(); | ||
} | ||
|
||
private static void checkNoSlf4j(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "org.slf4j").isEmpty(); | ||
} | ||
|
||
private static void checkNoJavaIoUtil(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.github.nbbrd.java-io-util").isEmpty(); | ||
} | ||
|
||
private static void checkDemetra(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "eu.europa.ec.joinup.sat") | ||
.has(sameVersion()) | ||
.extracting(NbmMavenClassPath.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("demetra-common"); | ||
} | ||
|
||
private static ListAssert<? extends NbmMavenClassPath.GAV> assertThatGroupId(List<? extends NbmMavenClassPath.GAV> coordinates, String groupId) { | ||
return assertThat(coordinates) | ||
.describedAs("Check " + groupId) | ||
.filteredOn(NbmMavenClassPath.GAV::getGroupId, groupId); | ||
} | ||
|
||
private static Condition<List<? extends NbmMavenClassPath.GAV>> sameVersion() { | ||
return new Condition<>(NbmMavenClassPath.GAV::haveSameVersion, "same version"); | ||
} | ||
|
||
private static List<NbmMavenClassPath.GAV> getRuntimeDependencies() throws IOException { | ||
return FileParser.onParsingStream(Manifest::new) | ||
.andThen(NbmMavenClassPath::parse) | ||
.parseResource(RuntimeDependenciesTest.class, "/runtime-dependencies.mf"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
nbdemetra-core/src/main/java/ec/nbdemetra/core/NbmMavenClassPath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ec.nbdemetra.core; | ||
|
||
import lombok.NonNull; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.jar.Manifest; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@lombok.experimental.UtilityClass | ||
public class NbmMavenClassPath { | ||
|
||
public static @NonNull List<GAV> parse(@NonNull Manifest manifest) { | ||
String items = manifest.getMainAttributes().getValue("Maven-Class-Path"); | ||
return items != null | ||
? splitAsStream(items, ' ').map(GAV::parse).collect(Collectors.toList()) | ||
: Collections.emptyList(); | ||
} | ||
|
||
private static Stream<String> splitAsStream(String items, char sep) { | ||
return Arrays.stream(items.split(String.valueOf(sep), -1)); | ||
} | ||
|
||
@lombok.Value | ||
public static class GAV { | ||
|
||
public static @NonNull GAV parse(@NonNull CharSequence input) throws IllegalArgumentException { | ||
String[] items = input.toString().split(":", -1); | ||
if (items.length != 3) { | ||
throw new IllegalArgumentException("Invalid GAV: '" + input + "'"); | ||
} | ||
return new GAV(items[0], items[1], items[2]); | ||
} | ||
|
||
@NonNull String groupId; | ||
@NonNull String artifactId; | ||
@NonNull String version; | ||
|
||
public static boolean haveSameVersion(@NonNull List<? extends GAV> list) { | ||
return list | ||
.stream() | ||
.map(GAV::getVersion) | ||
.distinct() | ||
.count() == 1; | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
nbdemetra-core/src/test/java/ec/nbdemetra/core/RuntimeDependenciesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ec.nbdemetra.core; | ||
|
||
import nbbrd.io.FileParser; | ||
import org.assertj.core.api.Condition; | ||
import org.assertj.core.api.ListAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.jar.Manifest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class RuntimeDependenciesTest { | ||
|
||
@Test | ||
public void test() throws IOException { | ||
assertThat(getRuntimeDependencies()) | ||
.describedAs("Check runtime dependencies") | ||
.satisfies(RuntimeDependenciesTest::checkDemetra) | ||
.satisfies(RuntimeDependenciesTest::checkJavaIoUtil) | ||
.satisfies(RuntimeDependenciesTest::checkSlf4j) | ||
.satisfies(RuntimeDependenciesTest::checkGuava) | ||
.hasSize(21); | ||
} | ||
|
||
private static void checkGuava(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.google.guava") | ||
.extracting(NbmMavenClassPath.GAV::getArtifactId) | ||
.contains("guava") | ||
.hasSize(3); | ||
} | ||
|
||
private static void checkSlf4j(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "org.slf4j") | ||
.has(sameVersion()) | ||
.extracting(NbmMavenClassPath.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("slf4j-api", "slf4j-jdk14", "jcl-over-slf4j"); | ||
} | ||
|
||
private static void checkJavaIoUtil(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.github.nbbrd.java-io-util") | ||
.has(sameVersion()) | ||
.hasSize(3); | ||
} | ||
|
||
private static void checkDemetra(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "eu.europa.ec.joinup.sat") | ||
.has(sameVersion()) | ||
.extracting(NbmMavenClassPath.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("demetra-tss", "demetra-tstoolkit", "demetra-utils", "demetra-workspace"); | ||
} | ||
|
||
private static ListAssert<? extends NbmMavenClassPath.GAV> assertThatGroupId(List<? extends NbmMavenClassPath.GAV> coordinates, String groupId) { | ||
return assertThat(coordinates) | ||
.describedAs("Check " + groupId) | ||
.filteredOn(NbmMavenClassPath.GAV::getGroupId, groupId); | ||
} | ||
|
||
private static Condition<List<? extends NbmMavenClassPath.GAV>> sameVersion() { | ||
return new Condition<>(NbmMavenClassPath.GAV::haveSameVersion, "same version"); | ||
} | ||
|
||
private static List<NbmMavenClassPath.GAV> getRuntimeDependencies() throws IOException { | ||
return FileParser.onParsingStream(Manifest::new) | ||
.andThen(NbmMavenClassPath::parse) | ||
.parseResource(RuntimeDependenciesTest.class, "/runtime-dependencies.mf"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
nbdemetra-jdbc/src/test/java/ec/nbdemetra/jdbc/RuntimeDependenciesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ec.nbdemetra.jdbc; | ||
|
||
import ec.nbdemetra.core.NbmMavenClassPath; | ||
import nbbrd.io.FileParser; | ||
import org.assertj.core.api.Condition; | ||
import org.assertj.core.api.ListAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.jar.Manifest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class RuntimeDependenciesTest { | ||
|
||
@Test | ||
public void test() throws IOException { | ||
assertThat(getRuntimeDependencies()) | ||
.describedAs("Check runtime dependencies") | ||
.satisfies(RuntimeDependenciesTest::checkDemetra) | ||
.satisfies(RuntimeDependenciesTest::checkJavaSqlUtil) | ||
.satisfies(RuntimeDependenciesTest::checkNoJavaIoUtil) | ||
.satisfies(RuntimeDependenciesTest::checkNoSlf4j) | ||
.satisfies(RuntimeDependenciesTest::checkNoGuava) | ||
.hasSize(2); | ||
} | ||
|
||
private static void checkNoGuava(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.google.guava").isEmpty(); | ||
} | ||
|
||
private static void checkNoSlf4j(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "org.slf4j").isEmpty(); | ||
} | ||
|
||
private static void checkNoJavaIoUtil(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.github.nbbrd.java-io-util").isEmpty(); | ||
} | ||
|
||
private static void checkJavaSqlUtil(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.github.nbbrd.java-sql-util") | ||
.has(sameVersion()) | ||
.extracting(NbmMavenClassPath.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("java-sql-jdbc"); | ||
} | ||
|
||
private static void checkDemetra(List<? extends NbmMavenClassPath.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "eu.europa.ec.joinup.sat") | ||
.has(sameVersion()) | ||
.extracting(NbmMavenClassPath.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("demetra-jdbc"); | ||
} | ||
|
||
private static ListAssert<? extends NbmMavenClassPath.GAV> assertThatGroupId(List<? extends NbmMavenClassPath.GAV> coordinates, String groupId) { | ||
return assertThat(coordinates) | ||
.describedAs("Check " + groupId) | ||
.filteredOn(NbmMavenClassPath.GAV::getGroupId, groupId); | ||
} | ||
|
||
private static Condition<List<? extends NbmMavenClassPath.GAV>> sameVersion() { | ||
return new Condition<>(NbmMavenClassPath.GAV::haveSameVersion, "same version"); | ||
} | ||
|
||
private static List<NbmMavenClassPath.GAV> getRuntimeDependencies() throws IOException { | ||
return FileParser.onParsingStream(Manifest::new) | ||
.andThen(NbmMavenClassPath::parse) | ||
.parseResource(RuntimeDependenciesTest.class, "/runtime-dependencies.mf"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.