Skip to content

Commit 6f657a2

Browse files
committed
Pull request #252: Development
Merge in ITB/itb-commons from development to master * commit 'f6a6ab5804f839f5d205d08b2748ceecd31e1eb1': Upgrade Spring Boot and JSON validation library Quality improvements
2 parents 2280b7b + f6a6ab5 commit 6f657a2

File tree

10 files changed

+64
-56
lines changed

10 files changed

+64
-56
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4141
<sonar.organization>isaitb</sonar.organization>
4242
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
43-
<version.springBoot>3.2.6</version.springBoot>
43+
<version.springBoot>3.3.1</version.springBoot>
4444
<version.jakartaAnnotationApi>2.1.1</version.jakartaAnnotationApi>
45-
<version.gitbTypes>1.22.0</version.gitbTypes>
45+
<version.gitbTypes>1.23.0</version.gitbTypes>
4646
<version.commonsLang>3.14.0</version.commonsLang>
4747
<version.commonsConfiguration>2.10.1</version.commonsConfiguration>
4848
<version.commonsIo>2.12.0</version.commonsIo>
@@ -65,7 +65,7 @@
6565
<version.jws>3.0.0</version.jws>
6666
<version.commonsBeanutils>1.9.4</version.commonsBeanutils>
6767
<version.jakartaActivation>2.1.2</version.jakartaActivation>
68-
<version.json-schema-validator>1.4.0</version.json-schema-validator>
68+
<version.json-schema-validator>1.4.2</version.json-schema-validator>
6969
<version.jakartaJson>2.0.0</version.jakartaJson>
7070
<version.jayway>2.9.0</version.jayway>
7171
<version.gson>2.9.0</version.gson>

validation-commons-report/src/test/java/eu/europa/ec/itb/validation/commons/report/ReportGeneratorBeanTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ void testWriteReportFromObject() throws Exception {
7575
var reportGenerator = mock(ReportGenerator.class);
7676
doAnswer((Answer<?>) invocation -> {
7777
assertSame(tar, invocation.getArgument(0));
78-
assertTrue(invocation.getArgument(1) instanceof FileOutputStream);
79-
assertTrue(invocation.getArgument(2) instanceof Function);
78+
assertInstanceOf(FileOutputStream.class, invocation.getArgument(1));
79+
assertInstanceOf(Function.class, invocation.getArgument(2));
8080
var result = ((Function)invocation.getArgument(2)).apply(null);
81-
assertTrue(result instanceof ReportLabels);
81+
assertInstanceOf(ReportLabels.class, result);
8282
assertEquals("Title1", ((ReportLabels) result).getTitle());
8383
return null;
8484
}).when(reportGenerator).writeTARReport(any(TAR.class), any(), any(), anyBoolean());
8585
var bean = createBean(reportGenerator);
86-
assertDoesNotThrow(() -> bean.writeReport(tar, outputFile.toFile(), (report) -> labels, false));
86+
assertDoesNotThrow(() -> bean.writeReport(tar, outputFile.toFile(), report -> labels, false));
8787
verify(reportGenerator, times(1)).writeTARReport(any(TAR.class), any(), any(), anyBoolean());
8888
// Alternate call.
8989
reset(reportGenerator);
@@ -101,15 +101,15 @@ void testWriteReportFromObjectError() throws Exception {
101101
var reportGenerator = mock(ReportGenerator.class);
102102
doAnswer((Answer<?>) invocation -> {
103103
assertSame(tar, invocation.getArgument(0));
104-
assertTrue(invocation.getArgument(1) instanceof FileOutputStream);
105-
assertTrue(invocation.getArgument(2) instanceof Function);
104+
assertInstanceOf(FileOutputStream.class, invocation.getArgument(1));
105+
assertInstanceOf(Function.class, invocation.getArgument(2));
106106
var result = ((Function)invocation.getArgument(2)).apply(null);
107-
assertTrue(result instanceof ReportLabels);
107+
assertInstanceOf(ReportLabels.class, result);
108108
assertEquals("Title1", ((ReportLabels) result).getTitle());
109109
throw new IllegalStateException();
110110
}).when(reportGenerator).writeTARReport(any(TAR.class), any(), any(), anyBoolean());
111111
var bean = createBean(reportGenerator);
112-
assertThrows(ValidatorException.class, () -> bean.writeReport(tar, outputFile.toFile(), (report) -> labels, false));
112+
assertThrows(ValidatorException.class, () -> bean.writeReport(tar, outputFile.toFile(), report -> labels, false));
113113
verify(reportGenerator, times(1)).writeTARReport(any(TAR.class), any(), any(), anyBoolean());
114114
}
115115

@@ -123,16 +123,16 @@ void testWriteReportFromFile() throws Exception {
123123
var outputFile = Path.of(tmpPath.toString(), "report.pdf");
124124
var reportGenerator = mock(ReportGenerator.class);
125125
doAnswer((Answer<?>) invocation -> {
126-
assertTrue(invocation.getArgument(0) instanceof FileInputStream);
127-
assertTrue(invocation.getArgument(1) instanceof FileOutputStream);
128-
assertTrue(invocation.getArgument(2) instanceof Function);
126+
assertInstanceOf(FileInputStream.class, invocation.getArgument(0));
127+
assertInstanceOf(FileOutputStream.class, invocation.getArgument(1));
128+
assertInstanceOf(Function.class, invocation.getArgument(2));
129129
var result = ((Function)invocation.getArgument(2)).apply(null);
130-
assertTrue(result instanceof ReportLabels);
130+
assertInstanceOf(ReportLabels.class, result);
131131
assertEquals("Title1", ((ReportLabels) result).getTitle());
132132
return null;
133133
}).when(reportGenerator).writeTARReport(any(FileInputStream.class), any(), any(), anyBoolean());
134134
var bean = createBean(reportGenerator);
135-
assertDoesNotThrow(() -> bean.writeReport(inputFile.toFile(), outputFile.toFile(), (report) -> labels, false));
135+
assertDoesNotThrow(() -> bean.writeReport(inputFile.toFile(), outputFile.toFile(), report -> labels, false));
136136
verify(reportGenerator, times(1)).writeTARReport(any(FileInputStream.class), any(), any(), anyBoolean());
137137
// Alternate call.
138138
reset(reportGenerator);
@@ -151,16 +151,16 @@ void testWriteReportFromFileError() throws Exception {
151151
var outputFile = Path.of(tmpPath.toString(), "report.pdf");
152152
var reportGenerator = mock(ReportGenerator.class);
153153
doAnswer((Answer<?>) invocation -> {
154-
assertTrue(invocation.getArgument(0) instanceof FileInputStream);
155-
assertTrue(invocation.getArgument(1) instanceof FileOutputStream);
156-
assertTrue(invocation.getArgument(2) instanceof Function);
154+
assertInstanceOf(FileInputStream.class, invocation.getArgument(0));
155+
assertInstanceOf(FileOutputStream.class, invocation.getArgument(1));
156+
assertInstanceOf(Function.class, invocation.getArgument(2));
157157
var result = ((Function)invocation.getArgument(2)).apply(null);
158-
assertTrue(result instanceof ReportLabels);
158+
assertInstanceOf(ReportLabels.class, result);
159159
assertEquals("Title1", ((ReportLabels) result).getTitle());
160160
throw new IllegalStateException();
161161
}).when(reportGenerator).writeTARReport(any(FileInputStream.class), any(), any(), anyBoolean());
162162
var bean = createBean(reportGenerator);
163-
assertThrows(ValidatorException.class, () -> bean.writeReport(inputFile.toFile(), outputFile.toFile(), (report) -> labels, false));
163+
assertThrows(ValidatorException.class, () -> bean.writeReport(inputFile.toFile(), outputFile.toFile(), report -> labels, false));
164164
verify(reportGenerator, times(1)).writeTARReport(any(FileInputStream.class), any(), any(), anyBoolean());
165165
}
166166

validation-commons-report/src/test/java/eu/europa/ec/itb/validation/commons/report/ReportGeneratorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void setItemContent(TAR report, int index) {
109109
@Test
110110
void testWriteTARReportFromObject() {
111111
var pdfPath = Path.of(tmpPath.toString(), "report.pdf");
112-
assertDoesNotThrow(() -> new ReportGenerator().writeTARReport(createTAR(), Files.newOutputStream(pdfPath), (report) -> mockReportLabels(), false));
112+
assertDoesNotThrow(() -> new ReportGenerator().writeTARReport(createTAR(), Files.newOutputStream(pdfPath), report -> mockReportLabels(), false));
113113
assertTrue(Files.exists(pdfPath));
114114
assertTrue(Files.isRegularFile(pdfPath));
115115
}
@@ -121,7 +121,7 @@ void testWriteTARReportFromXML() throws JAXBException, DatatypeConfigurationExce
121121
var jaxbContext = JAXBContext.newInstance(TAR.class, TestCaseReportType.class, TestStepStatus.class);
122122
jaxbContext.createMarshaller().marshal(new JAXBElement<>(new QName("http://www.gitb.com/tr/v1/", "TestCaseReport"), TAR.class, report), Files.newOutputStream(xmlPath));
123123
var pdfPath = Path.of(tmpPath.toString(), "report.pdf");
124-
assertDoesNotThrow(() -> new ReportGenerator().writeTARReport(Files.newInputStream(xmlPath), Files.newOutputStream(pdfPath), (r) -> mockReportLabels(), false));
124+
assertDoesNotThrow(() -> new ReportGenerator().writeTARReport(Files.newInputStream(xmlPath), Files.newOutputStream(pdfPath), r -> mockReportLabels(), false));
125125
assertTrue(Files.exists(pdfPath));
126126
assertTrue(Files.isRegularFile(pdfPath));
127127
}

validation-commons-web/src/main/java/eu/europa/ec/itb/validation/commons/web/rest/model/ApiInfo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import io.swagger.v3.oas.annotations.media.Schema;
66

77
import java.util.*;
8-
import java.util.stream.Collectors;
98

109
/**
1110
* Object providing the information on the validator's supported domains and validation types.

validation-commons-web/src/test/java/eu/europa/ec/itb/validation/commons/web/JsonConfigTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
import javax.xml.datatype.DatatypeConfigurationException;
1010
import javax.xml.datatype.DatatypeFactory;
11-
import java.lang.System;
1211
import java.math.BigInteger;
1312
import java.util.GregorianCalendar;
1413

14+
import static org.junit.jupiter.api.Assertions.assertNotNull;
15+
1516
class JsonConfigTest {
1617

1718
private BAR createBAR() {
@@ -61,7 +62,7 @@ private TAR createTAR() throws DatatypeConfigurationException {
6162
@Test
6263
void testSerialize() throws JsonProcessingException, DatatypeConfigurationException {
6364
var mapper = JsonConfig.objectMapper();
64-
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(createTAR()));
65+
assertNotNull(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(createTAR()));
6566
}
6667

6768
}

validation-commons/src/main/java/eu/europa/ec/itb/validation/commons/BaseFileManager.java

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public File preprocessFileIfNeeded(DomainConfig domainConfig, String validationT
556556
* Run preprocessing on the provided file (considered as a validation artifact) to determine the final file to use in the
557557
* validator. Preprocessing only takes place if a preprocessor is defined by the validator and the relevant domain,
558558
* validation type and artifact type define a preprocessing artifact.
559-
*
559+
* <p>
560560
* Note that this method is internal and assumes that preprocessing should indeed proceed.
561561
*
562562
* @param domainConfig The domain configuration to check for preprocessing configuration.
@@ -640,7 +640,7 @@ public List<FileInfo> getPreconfiguredValidationArtifacts(DomainConfig domainCon
640640
*/
641641
private List<File> getLocalValidationArtifactFiles(DomainConfig domainConfig, String validationType, String artifactType) {
642642
List<File> localFileReferences = new ArrayList<>();
643-
String localFolderConfigValue = domainConfig.getArtifactInfo().get(validationType).get(StringUtils.defaultString(artifactType, TypedValidationArtifactInfo.DEFAULT_TYPE)).getLocalPath();
643+
String localFolderConfigValue = domainConfig.getArtifactInfo().get(validationType).get(Objects.toString(artifactType, TypedValidationArtifactInfo.DEFAULT_TYPE)).getLocalPath();
644644
if (StringUtils.isNotEmpty(localFolderConfigValue)) {
645645
String[] localFiles = StringUtils.split(localFolderConfigValue, ',');
646646
for (String localFile: localFiles) {
@@ -702,7 +702,7 @@ public List<FileInfo> getLocalValidationArtifacts(File fileOrFolder, String arti
702702
/**
703703
* Get the list of validation artifacts for the provided domain, validation type and artifact type that are loaded from
704704
* remote resources (i.e. provided as URLs).
705-
*
705+
* <p>
706706
* Remote files are loaded and cached as part of the validator's startup. As such this method does not actually make remote
707707
* calls but rather looks up the already cached local copies of the artifacts' files.
708708
*
@@ -825,20 +825,7 @@ public void resetRemoteFileCache() {
825825
domainLock.writeLock().lock();
826826
logger.debug("Locked cache for [{}]", domainConfig.getDomainName());
827827
for (String validationType: domainConfig.getType()) {
828-
boolean downloadsSucceeded = true;
829-
try {
830-
// Empty cache folder.
831-
File remoteConfigFolder = new File(new File(getRemoteFileCacheFolder(), domainConfig.getDomainName()), validationType);
832-
FileUtils.deleteQuietly(remoteConfigFolder);
833-
TypedValidationArtifactInfo typedArtifactInfo = domainConfig.getArtifactInfo().get(validationType);
834-
for (String artifactType: typedArtifactInfo.getTypes()) {
835-
if (!downloadRemoteFilesForArtifactType(artifactType, validationType, remoteConfigFolder, domainConfig, typedArtifactInfo)) {
836-
downloadsSucceeded = false;
837-
}
838-
}
839-
} finally {
840-
domainConfig.setRemoteArtefactStatus(validationType, downloadsSucceeded);
841-
}
828+
refreshFileCacheForValidationType(domainConfig, validationType);
842829
}
843830
} catch (ValidatorException e) {
844831
// Never allow configuration errors in one domain to prevent the others from being available.
@@ -857,6 +844,29 @@ public void resetRemoteFileCache() {
857844
}
858845
}
859846

847+
/**
848+
* Refresh the remote artefacts for the given validation type.
849+
*
850+
* @param domainConfig The domain configuration.
851+
* @param validationType The validation type to process.
852+
*/
853+
private void refreshFileCacheForValidationType(DomainConfig domainConfig, String validationType) {
854+
boolean downloadsSucceeded = true;
855+
try {
856+
// Empty cache folder.
857+
File remoteConfigFolder = new File(new File(getRemoteFileCacheFolder(), domainConfig.getDomainName()), validationType);
858+
FileUtils.deleteQuietly(remoteConfigFolder);
859+
TypedValidationArtifactInfo typedArtifactInfo = domainConfig.getArtifactInfo().get(validationType);
860+
for (String artifactType: typedArtifactInfo.getTypes()) {
861+
if (!downloadRemoteFilesForArtifactType(artifactType, validationType, remoteConfigFolder, domainConfig, typedArtifactInfo)) {
862+
downloadsSucceeded = false;
863+
}
864+
}
865+
} finally {
866+
domainConfig.setRemoteArtefactStatus(validationType, downloadsSucceeded);
867+
}
868+
}
869+
860870
/**
861871
* Process the remote files for a given artifact type ensuring that errors do not propagate.
862872
*
@@ -870,11 +880,11 @@ public void resetRemoteFileCache() {
870880
private boolean downloadRemoteFilesForArtifactType(String artifactType, String validationType, File remoteConfigFolder, DomainConfig domainConfig, TypedValidationArtifactInfo typedArtifactInfo) {
871881
var result = false;
872882
try {
873-
artifactType = StringUtils.defaultString(artifactType, TypedValidationArtifactInfo.DEFAULT_TYPE);
883+
artifactType = Objects.toString(artifactType, TypedValidationArtifactInfo.DEFAULT_TYPE);
874884
File remoteFolderForType = new File(remoteConfigFolder, artifactType);
875885
downloadRemoteFiles(domainConfig.getDomain(), typedArtifactInfo.get(artifactType).getRemoteArtifacts(), remoteFolderForType, artifactType);
876886
// Update cache map.
877-
String key = domainConfig.getDomainName() + "|" + validationType + "|" + StringUtils.defaultString(artifactType, TypedValidationArtifactInfo.DEFAULT_TYPE);
887+
String key = domainConfig.getDomainName() + "|" + validationType + "|" + Objects.toString(artifactType, TypedValidationArtifactInfo.DEFAULT_TYPE);
878888
preconfiguredRemoteArtifactMap.put(key, getRemoteValidationArtifacts(domainConfig, validationType, artifactType));
879889
result = true;
880890
} catch (ValidatorException e) {

validation-commons/src/main/java/eu/europa/ec/itb/validation/commons/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
public class Utils {
4141

4242
private static final JAXBContext tdlJaxbContext;
43-
private final static PolicyFactory REPORT_ITEM_POLICY = (new HtmlPolicyBuilder())
43+
private static final PolicyFactory REPORT_ITEM_POLICY = (new HtmlPolicyBuilder())
4444
.allowStandardUrlProtocols()
4545
.allowElements("a")
4646
.allowAttributes("href")

validation-commons/src/main/java/eu/europa/ec/itb/validation/commons/artifact/TypedValidationArtifactInfo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.HashMap;
66
import java.util.Map;
7+
import java.util.Objects;
78
import java.util.Set;
89

910
/**
@@ -30,7 +31,7 @@ public ValidationArtifactInfo get() {
3031
* @return The artifact's information.
3132
*/
3233
public ValidationArtifactInfo get(String artifactType) {
33-
return perArtifactTypeMap.get(StringUtils.defaultString(artifactType, DEFAULT_TYPE));
34+
return perArtifactTypeMap.get(Objects.toString(artifactType, DEFAULT_TYPE));
3435
}
3536

3637
/**
@@ -40,7 +41,7 @@ public ValidationArtifactInfo get(String artifactType) {
4041
* @param artifactInfo The type's information.
4142
*/
4243
public void add(String artifactType, ValidationArtifactInfo artifactInfo) {
43-
perArtifactTypeMap.put(StringUtils.defaultString(artifactType, DEFAULT_TYPE), artifactInfo);
44+
perArtifactTypeMap.put(Objects.toString(artifactType, DEFAULT_TYPE), artifactInfo);
4445
}
4546

4647
/**

validation-commons/src/main/java/eu/europa/ec/itb/validation/commons/config/DomainConfigCache.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected DomainConfigCache() {
6767

6868
/**
6969
* Initialisation method to load all domain configurations.
70-
*
70+
* <p>
7171
* Additional customisations can be included by overriding the init() method.
7272
*/
7373
@PostConstruct
@@ -212,7 +212,7 @@ public T getConfigForDomain(String domain) {
212212

213213
if (domainConfig.getValidationTypeAlias() != null) {
214214
for (String alias: domainConfig.getValidationTypeAlias().keySet()) {
215-
if (domainConfig.resolveAlias(alias) == null) {
215+
if (domainConfig.resolveAlias(alias) == null && logger.isWarnEnabled()) {
216216
logger.warn("Invalid configuration for domain [{}]. Alias [{}] points to missing (full) validation type [{}].", domain, alias, domainConfig.getValidationTypeAlias().get(alias));
217217
}
218218
}
@@ -606,7 +606,7 @@ protected void addValidationArtifactInfoForType(String artifactType, String root
606606
if (!domainConfig.getArtifactInfo().containsKey(validationType)) {
607607
domainConfig.getArtifactInfo().put(validationType, new TypedValidationArtifactInfo());
608608
}
609-
domainConfig.getArtifactInfo().get(validationType).add(StringUtils.defaultString(artifactType, TypedValidationArtifactInfo.DEFAULT_TYPE), info);
609+
domainConfig.getArtifactInfo().get(validationType).add(Objects.toString(artifactType, TypedValidationArtifactInfo.DEFAULT_TYPE), info);
610610
}
611611
}
612612

validation-commons/src/test/java/eu/europa/ec/itb/validation/commons/UtilsTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
import eu.europa.ec.itb.validation.commons.test.BaseTest;
1111
import org.apache.commons.lang3.LocaleUtils;
1212
import org.junit.jupiter.api.Test;
13-
import org.w3c.dom.ls.LSResourceResolver;
14-
import org.xml.sax.ErrorHandler;
1513
import org.xml.sax.SAXException;
16-
import org.xml.sax.SAXParseException;
1714

1815
import javax.xml.parsers.DocumentBuilderFactory;
1916
import javax.xml.parsers.ParserConfigurationException;
2017
import javax.xml.stream.XMLInputFactory;
21-
import javax.xml.stream.XMLStreamException;
2218
import javax.xml.transform.OutputKeys;
2319
import javax.xml.transform.TransformerException;
2420
import javax.xml.transform.TransformerFactory;
@@ -38,7 +34,8 @@
3834
import static org.junit.jupiter.api.Assertions.*;
3935
import static org.mockito.ArgumentMatchers.any;
4036
import static org.mockito.ArgumentMatchers.eq;
41-
import static org.mockito.Mockito.*;
37+
import static org.mockito.Mockito.mock;
38+
import static org.mockito.Mockito.when;
4239

4340
class UtilsTest extends BaseTest {
4441

0 commit comments

Comments
 (0)