Skip to content

Commit

Permalink
Merge pull request #200 from com-pas/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
Dennis Labordus authored Nov 23, 2022
2 parents bd204ad + 978d6fa commit 01e814b
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 143 deletions.
9 changes: 1 addition & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ updates:
interval: "daily"
open-pull-requests-limit: 5
ignore:
# Next two dependencies shouldn't be upgrade, because Quarkus isn't using newer version of EL.
- dependency-name: org.hibernate.validator:hibernate-validator
versions: [ "[7.0,)" ]
- dependency-name: org.glassfish:jakarta.el
versions: [ "[4.0,)" ]
# Next two dependencies shouldn't be upgrade, because RestEasy isn't using newer version. (2.3.X)
- dependency-name: jakarta.xml.bind:jakarta.xml.bind-api
versions: [ "[3.0,)" ]
# Next dependencies shouldn't be upgrade, because RestEasy isn't using newer version. (2.3.X)
- dependency-name: com.sun.xml.bind:jaxb-impl
versions: [ "[3.0,)" ]
4 changes: 2 additions & 2 deletions .github/workflows/build-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 1.11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@v21
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
# Extract the tag name from the git reference, value of GITHUB_REF will be something like refs/tags/<tag_name>.
run: echo "##[set-output name=tagname;]$(echo ${GITHUB_REF##*/})"

- name: Set up JDK 1.11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@v21
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Set up JDK 1.11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Set Common Sonar Variables
id: sonar_env
Expand Down
20 changes: 18 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
# 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.8.4/apache-maven-3.8.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
11 changes: 6 additions & 5 deletions commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ SPDX-License-Identifier: Apache-2.0
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -67,11 +73,6 @@ SPDX-License-Identifier: Apache-2.0
<artifactId>jakarta.el</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.openpojo</groupId>
<artifactId>openpojo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ public T unmarshall(final InputStream xml) {
}
}

@SuppressWarnings("unchecked")
private T cast(Object result) {
if (!result.getClass().isAssignableFrom(getResultClass())) {
throw new CompasException(UNMARSHAL_ERROR_CODE, "Error unmarshalling to the Class. Invalid class");
}
return (T) result;
return getResultClass().cast(result);
}

public abstract static class Builder<W extends MarshallerWrapper<T>, T> {
Expand Down Expand Up @@ -145,7 +144,7 @@ private List<String> getContextPaths(List<SchemaConfig> schemaConfigs) {
// Convert the SchemaConfig List to a List containing only the ContextPaths.
return schemaConfigs.stream()
.map(SchemaConfig::getContextPath)
.collect(Collectors.toList());
.toList();
}

private String getImportStatements(List<SchemaConfig> schemaConfigs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static ClassLoader getClassLoader() {
classLoader = Resources.class.getClassLoader();
}
if (classLoader == null) {
throw new CompasException(NO_CLASS_LOADER_ERROR_CODE, "Unable to get ClassLoader for loading resouces");
throw new CompasException(NO_CLASS_LOADER_ERROR_CODE, "Unable to get ClassLoader for loading resources");
}
return classLoader;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@
public class FilenameConstraintValidator implements ConstraintValidator<FilenameValid, String> {
// Used a RegEx from Internet to check the strict one (Old Windows) to see if all matches.
private final Pattern pattern = Pattern.compile(
"# Match a valid Windows filename (unspecified file system).\n" +
"^ # Anchor to start of string.\n" +
"(?! # Assert filename is not: CON, PRN,\n" +
" (?: # AUX, NUL, COM1, COM2, COM3, COM4,\n" +
" CON|PRN|AUX|NUL| # COM5, COM6, COM7, COM8, COM9,\n" +
" COM[1-9]|LPT[1-9] # LPT1, LPT2, LPT3, LPT4, LPT5,\n" +
" ) # LPT6, LPT7, LPT8, and LPT9...\n" +
" (?:\\.[^.]*)? # followed by optional extension\n" +
" $ # and end of string\n" +
") # End negative lookahead assertion.\n" +
"[^<>:\"/\\\\|?*\\x00-\\x1F]* # Zero or more valid filename chars.\n" +
"[^<>:\"/\\\\|?*\\x00-\\x1F\\ .] # Last char is not a space or dot.\n" +
"$ # Anchor to end of string.",
"""
# Match a valid Windows filename (unspecified file system).
^# Anchor to start of string.
(?!# Assert filename is not:
(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])# CON,PRN,AUX,NUL,COM1-9,LPT1-9
(?:\\.[^.]*)?# followed by optional extension
$)# End negative lookahead assertion.
[^<>:"/\\\\|?*\\x00-\\x1F]*# Zero or more valid filename chars.
[^<>:"/\\\\|?*\\x00-\\x1F .]$# Last char is not a space or dot.
""",
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.COMMENTS);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ElementConverterTest {
"<SCL xmlns=\"" + SIMPLE_SCL_NS + "\" version=\"2007\" revision=\"B\" release=\"4\">" +
"</SCL>";

private ElementConverter converter = new ElementConverter();
private final ElementConverter converter = new ElementConverter();

@Test
void convertToString_WhenCalledWithXMLElementWithoutDeclaration_ThenElementConvertedToAString() throws ParserConfigurationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void marshaller_WhenInitializedWithEmptyConfig_ThenExceptionIsThrown() {
new XmlElementPojoMarshallerWrapper.Builder().withProperties("invalid-configs/marshaller-empty-config.yml");

// Expected that creation to fail, because there are no schemas configured.
var exception = assertThrows(CompasException.class, () -> marshallerWrapperBuilder.build());
var exception = assertThrows(CompasException.class, marshallerWrapperBuilder::build);
assertEquals(CONFIGURATION_ERROR_CODE, exception.getErrorCode());
}

Expand All @@ -56,7 +56,7 @@ void marshaller_WhenInitializedWithInvalidConfig_ThenExceptionIsThrown() {
new XmlElementPojoMarshallerWrapper.Builder().withProperties("invalid-configs/marshaller-invalid-config.yml");

// Expected that creation to fail, because this configuration is invalid.
var exception = assertThrows(CompasException.class, () -> marshallerWrapperBuilder.build());
var exception = assertThrows(CompasException.class, marshallerWrapperBuilder::build);
assertEquals(PROPERTY_ERROR_ERROR_CODE, exception.getErrorCode());
}

Expand All @@ -66,7 +66,7 @@ void marshaller_WhenInitializedWithInvalidContextPath_ThenExceptionIsThrown() {
new XmlElementPojoMarshallerWrapper.Builder().withProperties("invalid-configs/marshaller-invalid-contextpath-config.yml");

// Expected that creation to fail, because this configuration is invalid.
var exception = assertThrows(CompasException.class, () -> marshallerWrapperBuilder.build());
var exception = assertThrows(CompasException.class, marshallerWrapperBuilder::build);
assertEquals(CREATION_ERROR_CODE, exception.getErrorCode());
}

Expand All @@ -76,7 +76,7 @@ void marshaller_WhenInitializedWithInvalidXsdPath_ThenExceptionIsThrown() {
new XmlElementPojoMarshallerWrapper.Builder().withProperties("invalid-configs/marshaller-invalid-xsdpath-config.yml");

// Expected that creation to fail, because this configuration is invalid.
var exception = assertThrows(CompasException.class, () -> marshallerWrapperBuilder.build());
var exception = assertThrows(CompasException.class, marshallerWrapperBuilder::build);
assertEquals(RESOURCE_NOT_FOUND_ERROR_CODE, exception.getErrorCode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class FilenameConstraintValidatorTest {

@BeforeEach
void setupValidator() {
var factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
try (var factory = Validation.buildDefaultValidatorFactory()) {
validator = factory.getValidator();
}
}

@Test
Expand Down Expand Up @@ -53,16 +54,6 @@ private void assertIncorrectName(String name) {
assertEquals(1, violations.size());
}

private static final class SimplePojo {
@FilenameValid
private final String name;

public SimplePojo(String name) {
this.name = name;
}

public String getName() {
return name;
}
private record SimplePojo(@FilenameValid String name) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ void setupValidator() throws ParserConfigurationException {
var documentBuilder = documentFactory.newDocumentBuilder();
document = documentBuilder.newDocument();

var factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
try (var factory = Validation.buildDefaultValidatorFactory()) {
validator = factory.getValidator();
}
}

@Test
Expand Down Expand Up @@ -78,7 +79,7 @@ void isValid_WhenCalledWithMultipleElementAndOneIncorrectNS_ThenViolationFound()

private static final class SimplePojo {
@XmlAnyElementValid(elementName = ELEMENT_NAME, elementNamespace = ELEMENT_NS)
private List<Element> elements = new ArrayList<>();
private final List<Element> elements = new ArrayList<>();

public List<Element> getElements() {
return elements;
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ SPDX-License-Identifier: Apache-2.0
<packaging>pom</packaging>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<compas.scl.xsd.version>0.0.4</compas.scl.xsd.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ void toResponse_WhenCalledWithException_ThenInternalServerErrorReturnedWithBody(
var exception = new CompasException(NO_CLASS_LOADER_ERROR_CODE, "Some message that will only be logged");
var handler = new CompasExceptionHandler();

var result = handler.toResponse(exception);
assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), result.getStatus());
var errorMessage = ((ErrorResponse) result.getEntity()).getErrorMessages().get(0);
assertEquals(exception.getErrorCode(), errorMessage.getCode());
assertEquals(exception.getMessage(), errorMessage.getMessage());
assertNull(errorMessage.getProperty());
try (var result = handler.toResponse(exception)) {
assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), result.getStatus());
var errorMessage = ((ErrorResponse) result.getEntity()).getErrorMessages().get(0);
assertEquals(exception.getErrorCode(), errorMessage.getCode());
assertEquals(exception.getMessage(), errorMessage.getMessage());
assertNull(errorMessage.getProperty());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ void toResponse_WhenCalledWithConstraintViolations_ThenInternalServerErrorReturn
var exception = new ConstraintViolationException(constraintViolations);
var handler = new ConstraintViolationExceptionHandler();

var result = handler.toResponse(exception);
assertEquals(BAD_REQUEST.getStatusCode(), result.getStatus());
var errorMessage = ((ErrorResponse) result.getEntity()).getErrorMessages().get(0);
assertEquals(VALIDATION_ERROR, errorMessage.getCode());
assertEquals(MESSAGE, errorMessage.getMessage());
assertEquals(PROPERTY, errorMessage.getProperty());
verifyNoMoreInteractions(constraintViolation, propertyPath);
try (var result = handler.toResponse(exception)) {
assertEquals(BAD_REQUEST.getStatusCode(), result.getStatus());
var errorMessage = ((ErrorResponse) result.getEntity()).getErrorMessages().get(0);
assertEquals(VALIDATION_ERROR, errorMessage.getCode());
assertEquals(MESSAGE, errorMessage.getMessage());
assertEquals(PROPERTY, errorMessage.getProperty());
verifyNoMoreInteractions(constraintViolation, propertyPath);
}
}

@Test
Expand All @@ -57,10 +58,11 @@ void toResponse_WhenCalledWithoutConstraintViolations_ThenInternalServerErrorRet
var exception = new ConstraintViolationException(constraintViolations);
var handler = new ConstraintViolationExceptionHandler();

var result = handler.toResponse(exception);
assertEquals(BAD_REQUEST.getStatusCode(), result.getStatus());
var response = (ErrorResponse) result.getEntity();
assertTrue(response.getErrorMessages().isEmpty());
verifyNoInteractions(constraintViolation, propertyPath);
try (var result = handler.toResponse(exception)) {
assertEquals(BAD_REQUEST.getStatusCode(), result.getStatus());
var response = (ErrorResponse) result.getEntity();
assertTrue(response.getErrorMessages().isEmpty());
verifyNoInteractions(constraintViolation, propertyPath);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ void toResponse_WhenCalledWithException_ThenInternalServerErrorReturnedWithBody(
var exception = new Exception("Some message that will only be logged");
var handler = new GenericExceptionHandler();

var result = handler.toResponse(exception);
assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), result.getStatus());
var errorMessage = ((ErrorResponse) result.getEntity()).getErrorMessages().get(0);
assertEquals(UNKNOWN_EXCEPTION_ERROR, errorMessage.getCode());
assertEquals(ERROR_MESSAGE, errorMessage.getMessage());
assertNull(errorMessage.getProperty());
try (var result = handler.toResponse(exception)) {
assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), result.getStatus());
var errorMessage = ((ErrorResponse) result.getEntity()).getErrorMessages().get(0);
assertEquals(UNKNOWN_EXCEPTION_ERROR, errorMessage.getCode());
assertEquals(ERROR_MESSAGE, errorMessage.getMessage());
assertNull(errorMessage.getProperty());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.lfenergy.compas.scl.extensions.commons.CompasExtensionsField.SCL_NAME;

class AbstractCompasExtensionsManagerTest {
private AbstractCompasExtensionsManager manager = new AbstractCompasExtensionsManager() {
private final AbstractCompasExtensionsManager manager = new AbstractCompasExtensionsManager() {
};

@Test
Expand Down
Loading

0 comments on commit 01e814b

Please sign in to comment.