Skip to content

Commit 9a64466

Browse files
author
Flurb
committed
Review comments
Signed-off-by: Flurb <[email protected]>
1 parent 32977d8 commit 9a64466

File tree

6 files changed

+51
-84
lines changed

6 files changed

+51
-84
lines changed

pom.xml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ SPDX-License-Identifier: Apache-2.0
2525
<sonarqube-plugin.version>3.2.0</sonarqube-plugin.version>
2626

2727
<compas.scl.xsd.version>0.0.4</compas.scl.xsd.version>
28-
2928
<compas.core.version>0.8.0</compas.core.version>
30-
<jaxb.bind.version>2.3.6</jaxb.bind.version>
3129

3230
<quarkus.platform.version>2.7.5.Final</quarkus.platform.version>
3331
<slf4j.version>1.7.36</slf4j.version>
@@ -108,12 +106,6 @@ SPDX-License-Identifier: Apache-2.0
108106
<version>${compas.core.version}</version>
109107
</dependency>
110108

111-
<dependency>
112-
<groupId>com.sun.xml.bind</groupId>
113-
<artifactId>jaxb-impl</artifactId>
114-
<version>${jaxb.bind.version}</version>
115-
</dependency>
116-
117109
<dependency>
118110
<groupId>org.eclipse.microprofile.openapi</groupId>
119111
<artifactId>microprofile-openapi-api</artifactId>
@@ -159,33 +151,6 @@ SPDX-License-Identifier: Apache-2.0
159151
</configuration>
160152
</plugin>
161153

162-
<plugin>
163-
<groupId>org.jvnet.jaxb2.maven2</groupId>
164-
<artifactId>maven-jaxb2-plugin</artifactId>
165-
<version>0.14.0</version>
166-
<dependencies>
167-
<dependency>
168-
<groupId>org.jvnet.jaxb2_commons</groupId>
169-
<artifactId>jaxb2-namespace-prefix</artifactId>
170-
<version>1.3</version>
171-
</dependency>
172-
</dependencies>
173-
<executions>
174-
<execution>
175-
<id>xjc</id>
176-
<goals>
177-
<goal>generate</goal>
178-
</goals>
179-
</execution>
180-
</executions>
181-
<configuration>
182-
<args>
183-
<arg>-extension</arg>
184-
<arg>-Xnamespace-prefix</arg>
185-
</args>
186-
</configuration>
187-
</plugin>
188-
189154
<plugin>
190155
<groupId>org.apache.maven.plugins</groupId>
191156
<artifactId>maven-surefire-plugin</artifactId>

validator/src/main/java/org/lfenergy/compas/scl/validator/xsd/SclInfo.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,18 @@ private void processStartElement(StartElement element) {
5151
}
5252
}
5353

54-
public String getVersion() {
55-
return version;
56-
}
57-
58-
public String getRevision() {
59-
return revision;
60-
}
61-
62-
public String getRelease() {
63-
return release;
64-
}
65-
6654
private XMLInputFactory getXMLInputFactory() {
6755
var xmlInputFactory = XMLInputFactory.newInstance();
6856
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
6957
return xmlInputFactory;
7058
}
59+
60+
public String getSclVersion() {
61+
var sclVersion = "";
62+
if (version != null) sclVersion += version;
63+
if (revision != null) sclVersion += revision;
64+
if (release != null) sclVersion += release;
65+
66+
return sclVersion;
67+
}
7168
}

validator/src/main/java/org/lfenergy/compas/scl/validator/xsd/XSDValidator.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public XSDValidator(List<ValidationError> errorList, String sclData) {
3636
this.errorList = errorList;
3737
this.sclData = sclData;
3838

39-
var sclVersion = getSclVersion(sclData);
39+
var info = new SclInfo(sclData);
40+
var sclVersion = info.getSclVersion();
4041

4142
try {
4243
var factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@@ -45,8 +46,7 @@ public XSDValidator(List<ValidationError> errorList, String sclData) {
4546
new StreamSource(getClass().getClassLoader().getResourceAsStream("xsd/SCL" + sclVersion + "/SCL.xsd")));
4647
validator = schema.newValidator();
4748
}
48-
catch(SAXException exception) {
49-
LOGGER.error("[XSD validation] SAXException: {}", exception.getMessage());
49+
catch (SAXException exception) {
5050
throw new SclValidatorException(LOADING_XSD_FILE_ERROR_CODE, exception.getMessage());
5151
}
5252

@@ -57,7 +57,7 @@ public void warning(SAXParseException exception) {
5757
var validationMessage = getXsdValidationMessage(exception);
5858

5959
validationError.setMessage(validationMessage);
60-
LOGGER.warn(validationMessage);
60+
LOGGER.debug(validationMessage);
6161
}
6262

6363
@Override
@@ -66,7 +66,7 @@ public void error(SAXParseException exception) {
6666
var validationMessage = getXsdValidationMessage(exception);
6767

6868
validationError.setMessage(validationMessage);
69-
LOGGER.error(validationMessage);
69+
LOGGER.debug(validationMessage);
7070
}
7171

7272
@Override
@@ -75,8 +75,8 @@ public void fatalError(SAXParseException exception) {
7575
var validationMessage = getXsdValidationMessage(exception);
7676

7777
validationError.setMessage(validationMessage);
78-
LOGGER.error(validationMessage);
79-
LOGGER.error("[XSD validation] fatal error for schema validation, stopping");
78+
LOGGER.debug(validationMessage);
79+
LOGGER.debug("[XSD validation] fatal error for schema validation, stopping");
8080
}
8181
} );
8282
}
@@ -100,21 +100,6 @@ private ValidationError addNewValidationError() {
100100
return validationError;
101101
}
102102

103-
private String getSclVersion(String sclData) {
104-
var sclInfo = new SclInfo(sclData);
105-
106-
var version = sclInfo.getVersion();
107-
var revision = sclInfo.getRevision();
108-
var release = sclInfo.getRelease();
109-
110-
var sclVersion = "";
111-
if (version != null) sclVersion += version;
112-
if (revision != null) sclVersion += revision;
113-
if (release != null) sclVersion += release;
114-
115-
return sclVersion;
116-
}
117-
118103
private String getXsdValidationMessage(SAXParseException exception) {
119104
return "[XSD validation] (line: " + exception.getLineNumber() + ", column: "
120105
+ exception.getColumnNumber() + "): " + exception.getMessage();

validator/src/test/java/org/lfenergy/compas/scl/validator/xsd/SclInfoTest.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,7 @@
1515

1616
class SclInfoTest {
1717
@Test
18-
void getSclInfo_WhenCalledWithValidSclFile_ThenSclInfoFromFileReturned() throws IOException {
19-
var scdFile = new File(getClass().getResource("/scl/example.scd").getFile());
20-
var sclInfo = new SclInfo(Files.readString(scdFile.toPath()));
21-
22-
assertNotNull(sclInfo.getVersion());
23-
assertNotNull(sclInfo.getRelease());
24-
assertNotNull(sclInfo.getRevision());
25-
assertEquals("2007", sclInfo.getVersion());
26-
assertEquals("4", sclInfo.getRelease());
27-
assertEquals("B", sclInfo.getRevision());
28-
}
29-
30-
@Test
31-
void getSclInfo_WhenCalledWithInvalidSclFile_ThenExceptionThrownDuringConstruction() throws IOException {
18+
void constructor_WhenCalledWithInvalidSclFile_ThenExceptionThrownDuringConstruction() throws IOException {
3219
var scdFile = new File(getClass().getResource("/scl/invalid.scd").getFile());
3320

3421
var path = scdFile.toPath();
@@ -37,4 +24,22 @@ void getSclInfo_WhenCalledWithInvalidSclFile_ThenExceptionThrownDuringConstructi
3724
var exception = assertThrows(SclValidatorException.class, () -> new SclInfo(content));
3825
assertEquals(LOADING_SCL_FILE_ERROR_CODE, exception.getErrorCode());
3926
}
27+
28+
@Test
29+
void getSclVersion_WhenCalledWithValidSclFile_ThenSclVersionFromFileReturned() throws IOException {
30+
var scdFile = new File(getClass().getResource("/scl/example.scd").getFile());
31+
var sclInfo = new SclInfo(Files.readString(scdFile.toPath()));
32+
33+
assertNotNull(sclInfo.getSclVersion());
34+
assertEquals("2007B4", sclInfo.getSclVersion());
35+
}
36+
37+
@Test
38+
void getSclVersion_WhenCalledWithSclFileWithMissingVersion_ThenSclVersionFromFileReturned() throws IOException {
39+
var scdFile = new File(getClass().getResource("/scl/validation/example-with-missing-version.scd").getFile());
40+
var sclInfo = new SclInfo(Files.readString(scdFile.toPath()));
41+
42+
assertNotNull(sclInfo.getSclVersion());
43+
assertEquals("", sclInfo.getSclVersion());
44+
}
4045
}

validator/src/test/java/org/lfenergy/compas/scl/validator/xsd/XSDValidatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void validate_WhenCalledWithSclDataContainingInvalidVersion_ThenExceptionIsThrow
5656
}
5757

5858
@Test
59-
void validate_WhenCalledWithSclDataContainingMissingdVersion_ThenExceptionIsThrown() throws IOException {
59+
void validate_WhenCalledWithSclDataContainingMissingVersion_ThenExceptionIsThrown() throws IOException {
6060
var errorList = new ArrayList<ValidationError>();
6161
try (var inputStream = getClass()
6262
.getResourceAsStream("/scl/validation/example-with-missing-version.scd")) {

validator/src/test/java/org/lfenergy/compas/scl/validator/xsd/resourceresolver/ResourceInputTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
99

1010
import java.io.IOException;
11+
import java.io.Reader;
1112
import java.nio.charset.StandardCharsets;
1213

1314
import static org.junit.jupiter.api.Assertions.*;
@@ -58,4 +59,18 @@ void setSystemId_WhenCalled_ThenCorrectValueIsSet() {
5859
resourceInput.setSystemId("10");
5960
assertEquals("10", resourceInput.getSystemId());
6061
}
62+
63+
@Test
64+
void notUsedSetters_WhenCalled_NoExceptionsAreThrown() {
65+
try {
66+
resourceInput.setBaseURI("baseURI");
67+
resourceInput.setByteStream(null);
68+
resourceInput.setCertifiedText(true);
69+
resourceInput.setCharacterStream(null);
70+
resourceInput.setEncoding("encoding");
71+
resourceInput.setStringData("stringData");
72+
} catch (Exception e) {
73+
fail("All setters without a body should be called without exceptions thrown");
74+
}
75+
}
6176
}

0 commit comments

Comments
 (0)