Skip to content

Commit

Permalink
Merge pull request #78 from OP-TED/feature/TEDEFO-2401-pre-release-ve…
Browse files Browse the repository at this point in the history
…rsions-in-sdk-downloader

Updated the Dependency factory to use SNAPSHOT versions only when unit testing.
  • Loading branch information
rousso authored Oct 18, 2023
2 parents 7ea3c87 + 344c3e7 commit a6002f8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
27 changes: 22 additions & 5 deletions src/main/java/eu/europa/ted/eforms/viewer/DependencyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,36 @@
import eu.europa.ted.efx.interfaces.TranslatorOptions;

public class DependencyFactory implements TranslatorDependencyFactory {
private Path sdkRoot;

@SuppressWarnings("unused")
private DependencyFactory() {}
final private Path sdkRoot;
final private boolean sdkSnapshotsAllowed;

/**
* Public constructor used by the EfxTranslator does not allow the use of
* SNAPSHOT versions of the SDK.
*
* @param sdkRoot The root directory where the SDK will be downloaded.
*/
public DependencyFactory(Path sdkRoot) {
this(sdkRoot, false);
}

/**
* Subclasses can use this constructor to allow the use of SNAPSHOT versions of
* the SDK.
*
* @param sdkRoot The root directory where the SDK will be downloaded.
* @param resolveSnapshots If true, SNAPSHOT versions of the SDK will be
* downloaded if needed.
*/
protected DependencyFactory(Path sdkRoot, boolean resolveSnapshots) {
this.sdkRoot = sdkRoot;
this.sdkSnapshotsAllowed = resolveSnapshots;
}

@Override
public SymbolResolver createSymbolResolver(String sdkVersion) {
try {
SdkDownloader.downloadSdk(sdkVersion, sdkRoot);
SdkDownloader.downloadSdk(sdkVersion, sdkRoot, this.sdkSnapshotsAllowed);

return ComponentFactory.getSymbolResolver(sdkVersion, sdkRoot);
} catch (InstantiationException | IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package eu.europa.ted.eforms.viewer;

import java.nio.file.Path;

/**
* Extends {@link DependencyFactory} to allow the use of SNAPSHOT versions when
* unit testing.
*/
public class DependencyFactoryForUnitTesting extends DependencyFactory {

public DependencyFactoryForUnitTesting(Path sdkRoot) {
super(sdkRoot, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void testEfxToXsl(String sdkVersion) throws IOException, InstantiationException
final String viewId = "X02";
final Path xsl =
XslGenerator.Builder
.create(new DependencyFactory(SDK_ROOT_DIR))
.create(new DependencyFactoryForUnitTesting(SDK_ROOT_DIR))
.build()
.generateFile(sdkVersion, NoticeViewer.getEfxPath(sdkVersion, viewId, SDK_ROOT_DIR),
NoticeViewerConstants.DEFAULT_TRANSLATOR_OPTIONS, true);
Expand Down Expand Up @@ -145,7 +145,7 @@ private void testGenerateHtmlFromString(final String language, final String noti
Files.readString(noticeXmlPath, NoticeViewerConstants.DEFAULT_CHARSET);
final Path xslPath =
XslGenerator.Builder
.create(new DependencyFactory(SDK_ROOT_DIR))
.create(new DependencyFactoryForUnitTesting(SDK_ROOT_DIR))
.build()
.generateFile(sdkVersion, NoticeViewer.getEfxPath(sdkVersion, viewId, SDK_ROOT_DIR),
NoticeViewerConstants.DEFAULT_TRANSLATOR_OPTIONS, true);
Expand Down

0 comments on commit a6002f8

Please sign in to comment.