Skip to content

Commit

Permalink
devonfw#1454 adjusted retrieval of template set xml download links
Browse files Browse the repository at this point in the history
converted maven settings string to maven settings file path
adjusted tests accordingly
moved string reader from tests to retrieveTemplateSetXmlDownloadLinks method
  • Loading branch information
jan-vcapgemini committed Mar 1, 2023
1 parent ee0316f commit 925de2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devonfw.cobigen.retriever;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -27,24 +28,28 @@ public class ArtifactRetriever {
private static final Logger LOG = LoggerFactory.getLogger(ArtifactRetriever.class);

/**
* Retrieves a list of maven artifact download URLs
* Retrieves a list of maven artifact download URLs by given groupIds and maven settings file
*
* @param groupIdsList grouIds for template-sets
* @param mavenSettings string of maven's settings.xml
* @param mavenSettingsFile Path to maven's settings.xml
* @return list of maven artifact download URLs
* @throws IOException if an error occurred while reading the settings file
*
*/
protected static List<URL> retrieveTemplateSetXmlDownloadLinks(List<String> groupIdsList, String mavenSettings) {
protected static List<URL> retrieveTemplateSetXmlDownloadLinks(List<String> groupIdsList, Path mavenSettingsFile)
throws IOException {

String mavenSettingsString = new String(Files.readAllBytes(mavenSettingsFile));

List<URL> downloadLinks = new ArrayList<>();

MavenSettingsModel model = MavenSettings.generateMavenSettingsModel(mavenSettings);
MavenSettingsModel model = MavenSettings.generateMavenSettingsModel(mavenSettingsString);

MavenSettingsProxyModel activeProxy = MavenSettings
.determineActiveProxy(MavenSettings.generateMavenSettingsModel(mavenSettings));
.determineActiveProxy(MavenSettings.generateMavenSettingsModel(mavenSettingsString));

List<MavenSettingsRepositoryModel> allActiveRepositories = MavenSettings
.retrieveRepositoriesFromMavenSettings(mavenSettings);
.retrieveRepositoriesFromMavenSettings(mavenSettingsString);

List<MavenSettingsRepositoryModel> repositoriesWhichAreUsingTheProxy = MavenProxy
.obtainRepositories(allActiveRepositories, activeProxy, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
import java.util.Arrays;
import java.util.List;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;

import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
import com.devonfw.cobigen.retriever.settings.MavenSettings;
import com.devonfw.cobigen.retriever.settings.to.model.MavenSettingsModel;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.junit.WireMockRule;

Expand All @@ -36,47 +33,12 @@ public class ArtifactRetrieverTest {
*/
private final static String testdataRoot = "src/test/resources/testdata/unittest/ArtifactRetrieverTest";

/**
* {@link MavenSettingsModel} without a proxy
*/
private static MavenSettingsModel modelNonProxy;

/**
* {@link MavenSettingsModel} with a proxy
*/
private static MavenSettingsModel modelProxy;

/**
* Maven settings string without a proxy
*/
private static String mavenSettingsNonProxy;

/**
* Maven settings string without a proxy
*/
private static String mavenSettingsProxy;

/**
* WireMock rule to initialize
*/
@Rule
public WireMockRule wireMockRule = new WireMockRule(options().disableRequestJournal());

/**
* Used to initialize data needed for the tests
*
* @throws Exception if reading the maven settings fails
*/
@BeforeClass
public static void setUpClass() throws Exception {

mavenSettingsNonProxy = new String(Files.readAllBytes(Paths.get(testdataRoot).resolve("settingsNonProxy.xml")));
mavenSettingsProxy = new String(Files.readAllBytes(Paths.get(testdataRoot).resolve("settingsProxy.xml")));

modelNonProxy = MavenSettings.generateMavenSettingsModel(mavenSettingsNonProxy);
modelProxy = MavenSettings.generateMavenSettingsModel(mavenSettingsProxy);
}

/**
* Tests a retrieval of download URLs using using a settings.xml and basic authentication
*
Expand All @@ -91,7 +53,9 @@ public void testRetrieveTemplateSetXmlDownloadLinksWithBasicAuthentication() thr

List<String> groupIds = Arrays.asList("com.devonfw.cobigen.templates");

List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds, mavenSettingsNonProxy);
List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds,
Paths.get(testdataRoot).resolve("settingsNonProxy.xml"));

assertThat(downloadUrls).contains(new URL(
"http://localhost:8080/artifactory/api/storage/libs-release-local/com/devonfw/cobigen/templates/crud-java-server-app/2021.08.001/crud-java-server-app-2021.08.001-template-set.xml"));
}
Expand All @@ -109,7 +73,9 @@ public void testRetrieveTemplateSetXmlDownloadLinksWithoutProxy() throws IOExcep

List<String> groupIds = Arrays.asList("com.devonfw.cobigen.templates");

List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds, mavenSettingsNonProxy);
List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds,
Paths.get(testdataRoot).resolve("settingsNonProxy.xml"));

assertThat(downloadUrls).contains(new URL(
"http://localhost:8080/artifactory/api/storage/libs-release-local/com/devonfw/cobigen/templates/crud-java-server-app/2021.08.001/crud-java-server-app-2021.08.001-template-set.xml"));
}
Expand All @@ -131,7 +97,9 @@ public void testRetrieveTemplateSetXmlDownloadLinksWithProxy() throws IOExceptio

List<String> groupIds = Arrays.asList("com.devonfw.cobigen.templates");

List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds, mavenSettingsProxy);
List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds,
Paths.get(testdataRoot).resolve("settingsProxy.xml"));

assertThat(downloadUrls).contains(new URL(
"http://localhost:8080/artifactory/api/storage/libs-release-local/com/devonfw/cobigen/templates/crud-java-server-app/2021.08.001/crud-java-server-app-2021.08.001-template-set.xml"));
}
Expand Down

0 comments on commit 925de2c

Please sign in to comment.