diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
new file mode 100644
index 00000000..346d645f
--- /dev/null
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
+wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
diff --git a/pom.xml b/pom.xml
index 8e9c30c8..9665a7b4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -795,9 +795,6 @@ limitations under the License.]]>
junit-platform-maven-plugin
${junit-platform-maven-plugin.version}
-
-
-
diff --git a/src/test/java/com/redhat/exhort/ExhortTest.java b/src/test/java/com/redhat/exhort/ExhortTest.java
index 8cd2da0c..74efe977 100644
--- a/src/test/java/com/redhat/exhort/ExhortTest.java
+++ b/src/test/java/com/redhat/exhort/ExhortTest.java
@@ -49,7 +49,7 @@ protected String getFileFromResource(String fileName, String... pathList) {
try {
var tmpDir = Files.createTempDirectory("exhort_test_");
tmpFile = Files.createFile(tmpDir.resolve(fileName));
- try (var is = getResourceAsStreamDecision(pathList)) {
+ try (var is = getResourceAsStreamDecision(this.getClass(), pathList)) {
if(Objects.nonNull(is)) {
Files.write(tmpFile, is.readAllBytes());
}
diff --git a/src/test/java/com/redhat/exhort/ExhortTest.java.orig b/src/test/java/com/redhat/exhort/ExhortTest.java.orig
index e1b9540c..5ab08ced 100644
--- a/src/test/java/com/redhat/exhort/ExhortTest.java.orig
+++ b/src/test/java/com/redhat/exhort/ExhortTest.java.orig
@@ -36,13 +36,8 @@ public class ExhortTest {
return new String(bytes);
}
-<<<<<<< HEAD
- private static InputStream getResourceAsStreamDecision(String[] list) throws IOException {
- InputStream resourceAsStreamFromModule = ExhortTest.class.getModule().getResourceAsStream(String.join("/", list));
-=======
public static InputStream getResourceAsStreamDecision(Class extends ExhortTest> theClass, String[] list) throws IOException {
InputStream resourceAsStreamFromModule = theClass.getModule().getResourceAsStream(String.join("/", list));
->>>>>>> 73f7443 (test: fix and tailor tests also for new java versions)
if (Objects.isNull(resourceAsStreamFromModule)) {
return theClass.getClassLoader().getResourceAsStream(String.join("/", list));
}
@@ -54,7 +49,11 @@ public class ExhortTest {
try {
var tmpDir = Files.createTempDirectory("exhort_test_");
tmpFile = Files.createFile(tmpDir.resolve(fileName));
+<<<<<<< HEAD
+ try (var is = getResourceAsStreamDecision(pathList)) {
+=======
try (var is = getResourceAsStreamDecision(this.getClass(), pathList)) {
+>>>>>>> java-enhanced-it-working
if(Objects.nonNull(is)) {
Files.write(tmpFile, is.readAllBytes());
}
diff --git a/src/test/java/com/redhat/exhort/impl/ExhortApiIT.java b/src/test/java/com/redhat/exhort/impl/ExhortApiIT.java
index 65561468..95fab6fa 100644
--- a/src/test/java/com/redhat/exhort/impl/ExhortApiIT.java
+++ b/src/test/java/com/redhat/exhort/impl/ExhortApiIT.java
@@ -61,7 +61,8 @@ class ExhortApiIT extends ExhortTest {
@BeforeAll
static void beforeAll() {
api = new ExhortApi();
- System.setProperty("EXHORT_DEV_MODE","true");
+ System.setProperty("RHDA_SOURCE","exhort-java-api-it");
+ System.setProperty("EXHORT_DEV_MODE","false");
ecoSystemsManifestNames = Map.of("golang", "go.mod","maven","pom.xml","npm","package.json","pypi","requirements.txt");
}
@@ -69,6 +70,7 @@ static void beforeAll() {
@Tag("IntegrationTest")
@AfterAll
static void afterAll() {
+ System.clearProperty("RHDA_SOURCE");
System.clearProperty("EXHORT_DEV_MODE");
api = null;
}
diff --git a/src/test/java/com/redhat/exhort/impl/ExhortApiIT.java.orig b/src/test/java/com/redhat/exhort/impl/ExhortApiIT.java.orig
new file mode 100644
index 00000000..97467047
--- /dev/null
+++ b/src/test/java/com/redhat/exhort/impl/ExhortApiIT.java.orig
@@ -0,0 +1,226 @@
+/*
+ * Copyright © 2023 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.redhat.exhort.impl;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.redhat.exhort.Api;
+import com.redhat.exhort.ExhortTest;
+import com.redhat.exhort.api.AnalysisReport;
+import com.redhat.exhort.api.ProviderReport;
+import com.redhat.exhort.providers.HelperExtension;
+import com.redhat.exhort.tools.Ecosystem;
+import com.redhat.exhort.tools.Operations;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mockStatic;
+
+@Tag("IntegrationTest")
+@ExtendWith(HelperExtension.class)
+@ExtendWith(MockitoExtension.class)
+class ExhortApiIT extends ExhortTest {
+
+ private static Api api;
+ private static Map ecoSystemsManifestNames;
+
+ private MockedStatic mockedOperations;
+ @BeforeAll
+ static void beforeAll() {
+ api = new ExhortApi();
+<<<<<<< HEAD
+ System.setProperty("EXHORT_DEV_MODE","true");
+=======
+ System.setProperty("RHDA_SOURCE","exhort-java-api-it");
+ System.setProperty("EXHORT_DEV_MODE","false");
+>>>>>>> java-enhanced-it-working
+ ecoSystemsManifestNames = Map.of("golang", "go.mod","maven","pom.xml","npm","package.json","pypi","requirements.txt");
+
+ }
+
+ @Tag("IntegrationTest")
+ @AfterAll
+ static void afterAll() {
+<<<<<<< HEAD
+=======
+ System.clearProperty("RHDA_SOURCE");
+>>>>>>> java-enhanced-it-working
+ System.clearProperty("EXHORT_DEV_MODE");
+ api = null;
+ }
+ @Tag("IntegrationTest")
+ @ParameterizedTest
+ @EnumSource(value = Ecosystem.Type.class, names = { "GOLANG", "MAVEN", "NPM", "PYTHON" })
+ void Integration_Test_End_To_End_Stack_Analysis(Ecosystem.Type packageManager) throws IOException, ExecutionException, InterruptedException {
+ String manifestFileName = ecoSystemsManifestNames.get(packageManager.getType());
+ String pathToManifest = getFileFromResource(manifestFileName, "tst_manifests", "it", packageManager.getType(), manifestFileName);
+ preparePythonEnvironment(packageManager);
+ // Github action runner with all maven and java versions seems to enter infinite loop in integration tests of MAVEN when runnig dependency maven plugin to produce verbose text dependenct tree format.
+ // locally it's not recreated with same versions
+ mockMavenDependencyTree(packageManager);
+ AnalysisReport analysisReportResult = api.stackAnalysis(pathToManifest).get();
+ handleJsonResponse(analysisReportResult,true);
+ releaseStaticMock(packageManager);
+ }
+
+ private void releaseStaticMock(Ecosystem.Type packageManager) {
+ if(packageManager.equals(Ecosystem.Type.MAVEN)) {
+ this.mockedOperations.close();
+ }
+ }
+
+
+ @Tag("IntegrationTest")
+ @ParameterizedTest
+ @EnumSource(value = Ecosystem.Type.class, names = { "GOLANG", "MAVEN", "NPM", "PYTHON" })
+ void Integration_Test_End_To_End_Stack_Analysis_Mixed(Ecosystem.Type packageManager) throws IOException, ExecutionException, InterruptedException {
+ String manifestFileName = ecoSystemsManifestNames.get(packageManager.getType());
+ String pathToManifest = getFileFromResource(manifestFileName, "tst_manifests", "it", packageManager.getType(), manifestFileName);
+ preparePythonEnvironment(packageManager);
+ // Github action runner with all maven and java versions seems to enter infinite loop in integration tests of MAVEN when runnig dependency maven plugin to produce verbose text dependenct tree format.
+ // locally it's not recreated with same versions
+ mockMavenDependencyTree(packageManager);
+ AnalysisReport analysisReportJson = api.stackAnalysisMixed(pathToManifest).get().json;
+ String analysisReportHtml = new String(api.stackAnalysisMixed(pathToManifest).get().html);
+ handleJsonResponse(analysisReportJson,true);
+ handleHtmlResponse(analysisReportHtml);
+ releaseStaticMock(packageManager);
+ }
+
+ @Tag("IntegrationTest")
+ @ParameterizedTest
+ @EnumSource(value = Ecosystem.Type.class, names = { "GOLANG", "MAVEN", "NPM", "PYTHON" })
+ void Integration_Test_End_To_End_Stack_Analysis_Html(Ecosystem.Type packageManager) throws IOException, ExecutionException, InterruptedException {
+ String manifestFileName = ecoSystemsManifestNames.get(packageManager.getType());
+ String pathToManifest = getFileFromResource(manifestFileName, "tst_manifests", "it", packageManager.getType(), manifestFileName);
+ preparePythonEnvironment(packageManager);
+ // Github action runner with all maven and java versions seems to enter infinite loop in integration tests of MAVEN when runnig dependency maven plugin to produce verbose text dependenct tree format.
+ // locally it's not recreated with same versions
+ mockMavenDependencyTree(packageManager);
+ String analysisReportHtml = new String(api.stackAnalysisHtml(pathToManifest).get());
+ releaseStaticMock(packageManager);
+ handleHtmlResponse(analysisReportHtml);
+ }
+
+
+ @Tag("IntegrationTest")
+ @ParameterizedTest
+ @EnumSource(value = Ecosystem.Type.class, names = { "GOLANG", "MAVEN", "NPM", "PYTHON" })
+ void Integration_Test_End_To_End_Component_Analysis(Ecosystem.Type packageManager) throws IOException, ExecutionException, InterruptedException {
+ String manifestFileName = ecoSystemsManifestNames.get(packageManager.getType());
+ byte[] manifestContent = getStringFromFile("tst_manifests", "it", packageManager.getType(), manifestFileName).getBytes();
+ preparePythonEnvironment(packageManager);
+ AnalysisReport analysisReportResult = api.componentAnalysis(manifestFileName,manifestContent).get();
+ handleJsonResponse(analysisReportResult,false);
+ }
+
+
+ private static void preparePythonEnvironment(Ecosystem.Type packageManager) {
+ if(packageManager.equals(Ecosystem.Type.PYTHON)) {
+ System.setProperty("EXHORT_PYTHON_VIRTUAL_ENV","true");
+ System.setProperty("EXHORT_PYTHON_INSTALL_BEST_EFFORTS","true");
+ System.setProperty("MATCH_MANIFEST_VERSIONS","false");
+ }
+ else {
+ System.clearProperty("EXHORT_PYTHON_VIRTUAL_ENV");
+ System.clearProperty("EXHORT_PYTHON_INSTALL_BEST_EFFORTS");
+ System.clearProperty("MATCH_MANIFEST_VERSIONS");
+ }
+ }
+
+ private static void handleJsonResponse(AnalysisReport analysisReportResult, boolean positiveNumberOfTransitives) {
+ analysisReportResult.getProviders().entrySet().stream().forEach(provider -> { assertTrue(provider.getValue().getStatus().getOk());
+ assertTrue(provider.getValue().getStatus().getCode() == HttpURLConnection.HTTP_OK);
+ });
+ analysisReportResult.getProviders().entrySet().stream()
+ .map(Map.Entry::getValue)
+ .map(ProviderReport::getSources)
+ .map(Map::entrySet)
+ .flatMap(Collection::stream)
+ .map(Map.Entry::getValue)
+ .forEach( source -> assertTrue(source.getSummary().getTotal() > 0 ));
+
+ if(positiveNumberOfTransitives) {
+ assertTrue(analysisReportResult.getScanned().getTransitive() > 0);
+ }
+ else {
+ assertEquals(0,analysisReportResult.getScanned().getTransitive());
+ }
+ }
+
+ private void handleHtmlResponse(String analysisReportHtml) throws JsonProcessingException {
+ ObjectMapper om = new ObjectMapper();
+ assertTrue(analysisReportHtml.contains("svg") && analysisReportHtml.contains("html"));
+ int jsonStart = analysisReportHtml.indexOf("\"report\":");
+ int jsonEnd = analysisReportHtml.indexOf("}}}}}");
+ String embeddedJson = analysisReportHtml.substring(jsonStart + 9 ,jsonEnd + 5);
+ JsonNode jsonInHtml = om.readTree(embeddedJson);
+ JsonNode scannedNode = jsonInHtml.get("scanned");
+ assertTrue(scannedNode.get("total").asInt(0) > 0);
+ assertTrue(scannedNode.get("transitive").asInt(0) > 0);
+ JsonNode status = jsonInHtml.get("providers").get("snyk").get("status");
+ assertTrue(status.get("code").asInt(0) == 200);
+ assertTrue(status.get("ok").asBoolean(false));
+
+ }
+ private void mockMavenDependencyTree(Ecosystem.Type packageManager) throws IOException {
+ if(packageManager.equals(Ecosystem.Type.MAVEN)) {
+ mockedOperations = mockStatic(Operations.class);
+ String depTree;
+ try (var is = getResourceAsStreamDecision(getClass(), new String [] { "tst_manifests", "it","maven", "depTree.txt"})) {
+ depTree = new String(is.readAllBytes());
+ }
+ mockedOperations.when(() -> Operations.runProcess(any(),any())).thenAnswer(invocationOnMock -> { return getOutputFileAndOverwriteItWithMock(depTree, invocationOnMock, "-DoutputFile");});
+ }
+ }
+
+ public static String getOutputFileAndOverwriteItWithMock(String outputFileContent, InvocationOnMock invocationOnMock, String parameterPrefix) throws IOException {
+ String[] rawArguments = (String[]) invocationOnMock.getRawArguments()[0];
+ Optional outputFileArg = Arrays.stream(rawArguments).filter(arg -> arg!= null && arg.startsWith(parameterPrefix)).findFirst();
+ String outputFilePath=null;
+ if(outputFileArg.isPresent())
+ {
+ String outputFile = outputFileArg.get();
+ outputFilePath = outputFile.substring(outputFile.indexOf("=") + 1);
+ Files.writeString(Path.of(outputFilePath), outputFileContent);
+ }
+ return outputFilePath;
+ }
+
+}
+
+
+
diff --git a/src/test/java/com/redhat/exhort/impl/Exhort_Api_Test.java b/src/test/java/com/redhat/exhort/impl/Exhort_Api_Test.java
index be2b2b55..5ac3e8c6 100644
--- a/src/test/java/com/redhat/exhort/impl/Exhort_Api_Test.java
+++ b/src/test/java/com/redhat/exhort/impl/Exhort_Api_Test.java
@@ -15,6 +15,7 @@
*/
package com.redhat.exhort.impl;
+import static com.redhat.exhort.ExhortTest.getResourceAsStreamDecision;
import static org.assertj.core.api.BDDAssertions.then;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
@@ -30,6 +31,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
+import com.redhat.exhort.ExhortTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -54,7 +56,7 @@
@ClearEnvironmentVariable(key="RHDA_TOKEN")
@ClearEnvironmentVariable(key="RHDA_SOURCE")
@SuppressWarnings("unchecked")
-class Exhort_Api_Test {
+class Exhort_Api_Test extends ExhortTest {
@Mock
Provider mockProvider;
@Mock
diff --git a/src/test/java/com/redhat/exhort/providers/Golang_Modules_Provider_Test.java b/src/test/java/com/redhat/exhort/providers/Golang_Modules_Provider_Test.java
index 7c678aa8..542fc01e 100644
--- a/src/test/java/com/redhat/exhort/providers/Golang_Modules_Provider_Test.java
+++ b/src/test/java/com/redhat/exhort/providers/Golang_Modules_Provider_Test.java
@@ -18,8 +18,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.exhort.Api;
import com.redhat.exhort.ExhortTest;
-import com.redhat.exhort.Provider;
-import com.redhat.exhort.sbom.Sbom;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
diff --git a/src/test/java/com/redhat/exhort/providers/PythonEnvironmentExtension.java b/src/test/java/com/redhat/exhort/providers/PythonEnvironmentExtension.java
index e5b7dffd..34a7fe35 100644
--- a/src/test/java/com/redhat/exhort/providers/PythonEnvironmentExtension.java
+++ b/src/test/java/com/redhat/exhort/providers/PythonEnvironmentExtension.java
@@ -58,7 +58,7 @@ public void beforeAll(ExtensionContext extensionContext) throws Exception {
// var tmpPythonModuleDir = Files.createTempDirectory("exhort_test_");
// var tmpPythonFile = Files.createFile(tmpPythonModuleDir.resolve("requirements.txt"));
// Python_Provider_Test.testFolders().forEach( test -> {
-// try (var is = getClass().getModule().getResourceAsStream(String.join("/","tst_manifests", "pip", test, "requirements.txt"))) {
+// try (var is = getClass().getClassLoader().getResourceAsStream(String.join("/","tst_manifests", "pip", test, "requirements.txt"))) {
// Files.write(tmpPythonFile, is.readAllBytes());
// pythonController.installPackage(tmpPythonFile.toAbsolutePath().toString());
//
diff --git a/src/test/java/com/redhat/exhort/providers/Python_Provider_Test.java b/src/test/java/com/redhat/exhort/providers/Python_Provider_Test.java
index 4aec53d1..1e3070aa 100644
--- a/src/test/java/com/redhat/exhort/providers/Python_Provider_Test.java
+++ b/src/test/java/com/redhat/exhort/providers/Python_Provider_Test.java
@@ -19,10 +19,8 @@
import com.redhat.exhort.ExhortTest;
import com.redhat.exhort.utils.PythonControllerBase;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;