Skip to content

Commit

Permalink
Merge pull request #146 from com-pas/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
Dennis Labordus authored Nov 15, 2022
2 parents 143905f + c18df0c commit ab314d7
Show file tree
Hide file tree
Showing 26 changed files with 176 additions and 219 deletions.
6 changes: 5 additions & 1 deletion app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ SPDX-License-Identifier: Apache-2.0

<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>jaxrs-commons</artifactId>
<artifactId>rest-commons</artifactId>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>websocket-commons</artifactId>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/app-jvm
#
###
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7

ARG JAVA_PACKAGE=java-17-openjdk-headless
ARG RUN_JAVA_VERSION=1.3.8
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# docker run -i --rm -p 8080:8080 quarkus/app
#
###
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.scl.validator.rest.exception;

import org.lfenergy.compas.core.jaxrs.model.ErrorResponse;
import org.lfenergy.compas.core.commons.model.ErrorResponse;
import org.lfenergy.compas.scl.validator.exception.NsdocFileNotFoundException;

import javax.ws.rs.core.Response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.quarkus.security.Authenticated;
import io.vertx.mutiny.core.eventbus.EventBus;
import org.lfenergy.compas.core.websocket.ErrorResponseEncoder;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.lfenergy.compas.scl.validator.rest.v1.event.SclValidatorEventRequest;
import org.lfenergy.compas.scl.validator.rest.v1.model.SclValidateRequest;
Expand All @@ -21,13 +22,14 @@
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;

import static org.lfenergy.compas.core.websocket.WebsocketSupport.handleException;
import static org.lfenergy.compas.scl.validator.rest.SclResourceConstants.TYPE_PATH_PARAM;

@Authenticated
@ApplicationScoped
@ServerEndpoint(value = "/validate-ws/v1/{" + TYPE_PATH_PARAM + "}",
decoders = {SclValidateRequestDecoder.class, SclValidateResponseDecoder.class},
encoders = {SclValidateRequestEncoder.class, SclValidateResponseEncoder.class})
encoders = {SclValidateRequestEncoder.class, SclValidateResponseEncoder.class, ErrorResponseEncoder.class})
public class SclValidatorServerEndpoint {
private static final Logger LOGGER = LoggerFactory.getLogger(SclValidatorServerEndpoint.class);

Expand All @@ -53,6 +55,7 @@ public void onMessage(Session session, SclValidateRequest request, @PathParam(TY
@OnError
public void onError(Session session, @PathParam(TYPE_PATH_PARAM) String type, Throwable throwable) {
LOGGER.warn("Error with session {} for type {}.", session.getId(), type, throwable);
handleException(session, throwable);
}

@OnClose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.lfenergy.compas.scl.validator.rest.v1.event;

import io.quarkus.vertx.ConsumeEvent;
import org.lfenergy.compas.core.websocket.WebsocketHandler;
import org.lfenergy.compas.scl.validator.rest.v1.model.SclValidateResponse;
import org.lfenergy.compas.scl.validator.service.SclValidatorService;

Expand All @@ -24,10 +25,10 @@ public SclValidatorEventHandler(SclValidatorService sclValidatorService) {

@ConsumeEvent(value = "validate-ws", blocking = true)
public void validateWebsocketsEvent(SclValidatorEventRequest request) {
var response = new SclValidateResponse();
response.setValidationErrorList(sclValidatorService.validate(request.getType(), request.getSclData()));

var session = request.getSession();
session.getAsyncRemote().sendObject(response);
new WebsocketHandler<SclValidateResponse>().execute(request.getSession(), () -> {
var response = new SclValidateResponse();
response.setValidationErrorList(sclValidatorService.validate(request.getType(), request.getSclData()));
return response;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,18 @@
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.scl.validator.rest.v1.websocket;

import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
import org.lfenergy.compas.core.websocket.AbstractDecoder;
import org.lfenergy.compas.core.websocket.WebsocketSupport;
import org.lfenergy.compas.scl.validator.rest.v1.model.SclValidateRequest;

import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
import javax.xml.bind.JAXBContext;
import java.io.StringReader;

import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.WEBSOCKET_DECODER_ERROR_CODE;

public class SclValidateRequestDecoder implements Decoder.Text<SclValidateRequest> {
@Override
public void init(EndpointConfig endpointConfig) {
// do nothing.
}

public class SclValidateRequestDecoder extends AbstractDecoder<SclValidateRequest> {
@Override
public boolean willDecode(String message) {
return (message != null);
}

@Override
public SclValidateRequest decode(String message) {
try {
var jaxbContext = JAXBContext.newInstance(SclValidateRequest.class);
var unmarshaller = jaxbContext.createUnmarshaller();
var reader = new StringReader(message);
return (SclValidateRequest) unmarshaller.unmarshal(reader);
} catch (Exception exp) {
throw new SclValidatorException(WEBSOCKET_DECODER_ERROR_CODE,
"Error unmarshalling SCL Validate Request from Websockets.",
exp);
}
}

@Override
public void destroy() {
// do nothing.
return WebsocketSupport.decode(message, SclValidateRequest.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,13 @@
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.scl.validator.rest.v1.websocket;

import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
import org.lfenergy.compas.core.websocket.AbstractEncoder;
import org.lfenergy.compas.core.websocket.WebsocketSupport;
import org.lfenergy.compas.scl.validator.rest.v1.model.SclValidateRequest;

import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import javax.xml.bind.JAXBContext;
import java.io.StringWriter;

import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.WEBSOCKET_ENCODER_ERROR_CODE;

public class SclValidateRequestEncoder implements Encoder.Text<SclValidateRequest> {
@Override
public void init(EndpointConfig endpointConfig) {
// do nothing.
}

@Override
public String encode(SclValidateRequest request) {
try {
var jaxbContext = JAXBContext.newInstance(SclValidateRequest.class);
var marshaller = jaxbContext.createMarshaller();

var st = new StringWriter();
marshaller.marshal(request, st);
return st.toString();
} catch (Exception exp) {
throw new SclValidatorException(WEBSOCKET_ENCODER_ERROR_CODE,
"Error marshalling SCL Validate Request from Websockets.",
exp);
}
}

public class SclValidateRequestEncoder extends AbstractEncoder<SclValidateRequest> {
@Override
public void destroy() {
// do nothing.
public String encode(SclValidateRequest jaxbObject) {
return WebsocketSupport.encode(jaxbObject, SclValidateRequest.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,18 @@
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.scl.validator.rest.v1.websocket;

import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
import org.lfenergy.compas.core.websocket.AbstractDecoder;
import org.lfenergy.compas.core.websocket.WebsocketSupport;
import org.lfenergy.compas.scl.validator.rest.v1.model.SclValidateResponse;

import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
import javax.xml.bind.JAXBContext;
import java.io.StringReader;

import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.WEBSOCKET_DECODER_ERROR_CODE;

public class SclValidateResponseDecoder implements Decoder.Text<SclValidateResponse> {
@Override
public void init(EndpointConfig endpointConfig) {
// do nothing.
}

public class SclValidateResponseDecoder extends AbstractDecoder<SclValidateResponse> {
@Override
public boolean willDecode(String message) {
return (message != null);
}

@Override
public SclValidateResponse decode(String message) {
try {
var jaxbContext = JAXBContext.newInstance(SclValidateResponse.class);
var unmarshaller = jaxbContext.createUnmarshaller();
var reader = new StringReader(message);
return (SclValidateResponse) unmarshaller.unmarshal(reader);
} catch (Exception exp) {
throw new SclValidatorException(WEBSOCKET_DECODER_ERROR_CODE,
"Error unmarshalling SCL Validate Response from Websockets.",
exp);
}
}

@Override
public void destroy() {
// do nothing.
return WebsocketSupport.decode(message, SclValidateResponse.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,13 @@
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.scl.validator.rest.v1.websocket;

import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
import org.lfenergy.compas.core.websocket.AbstractEncoder;
import org.lfenergy.compas.core.websocket.WebsocketSupport;
import org.lfenergy.compas.scl.validator.rest.v1.model.SclValidateResponse;

import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import javax.xml.bind.JAXBContext;
import java.io.StringWriter;

import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.WEBSOCKET_ENCODER_ERROR_CODE;

public class SclValidateResponseEncoder implements Encoder.Text<SclValidateResponse> {
@Override
public void init(EndpointConfig endpointConfig) {
// do nothing.
}

@Override
public String encode(SclValidateResponse response) {
try {
var jaxbContext = JAXBContext.newInstance(SclValidateResponse.class);
var marshaller = jaxbContext.createMarshaller();

var st = new StringWriter();
marshaller.marshal(response, st);
return st.toString();
} catch (Exception exp) {
throw new SclValidatorException(WEBSOCKET_ENCODER_ERROR_CODE,
"Error marshalling SCL Validate Response from Websockets.",
exp);
}
}

public class SclValidateResponseEncoder extends AbstractEncoder<SclValidateResponse> {
@Override
public void destroy() {
// do nothing.
public String encode(SclValidateResponse jaxbObject) {
return WebsocketSupport.encode(jaxbObject, SclValidateResponse.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class CompasSclValidatorConfigurationTest {
Expand All @@ -32,7 +33,7 @@ void createOclFileCollector_WhenCalled_ThenObjectReturned() {

assertNotNull(new CompasSclValidatorConfiguration().createOclFileCollector(validatorProperties));

verify(validatorProperties, times(1)).oclCustomDirectory();
verify(validatorProperties).oclCustomDirectory();
}

@Test
Expand All @@ -43,7 +44,7 @@ void createSclRiseClipseValidator_WhenCalled_ThenObjectReturned() {
oclFileCollector,
validatorProperties));

verify(validatorProperties, times(1)).tempDirectory();
verify(validatorProperties).tempDirectory();
}

@Test
Expand All @@ -58,6 +59,6 @@ void createNsdocFinder_WhenCalled_ThenObjectReturned() {
assertNotNull(new CompasSclValidatorConfiguration().createNsdocFinder(
validatorProperties));

verify(validatorProperties, times(1)).nsdocDirectory();
verify(validatorProperties).nsdocDirectory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package org.lfenergy.compas.scl.validator.rest.exception;

import org.junit.jupiter.api.Test;
import org.lfenergy.compas.core.jaxrs.model.ErrorResponse;
import org.lfenergy.compas.core.commons.model.ErrorResponse;
import org.lfenergy.compas.scl.validator.exception.NsdocFileNotFoundException;

import static javax.ws.rs.core.Response.Status.NOT_FOUND;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.quarkus.test.security.TestSecurity;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
import org.lfenergy.compas.core.jaxrs.JaxrsConstants;
import org.lfenergy.compas.scl.validator.exception.NsdocFileNotFoundException;
import org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode;
import org.lfenergy.compas.scl.validator.model.NsdocFile;
Expand All @@ -22,9 +21,11 @@
import static io.restassured.path.xml.config.XmlPathConfig.xmlPathConfig;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.lfenergy.compas.core.commons.CommonConstants.COMPAS_COMMONS_V1_NS_URI;
import static org.lfenergy.compas.scl.validator.SclValidatorConstants.SCL_VALIDATOR_SERVICE_V1_NS_URI;
import static org.lfenergy.compas.scl.validator.rest.SclResourceConstants.ID_PARAM;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@QuarkusTest
@TestHTTPEndpoint(NsdocResource.class)
Expand Down Expand Up @@ -52,7 +53,7 @@ void list_WhenCalled_ThenListReturned() {
var files = xmlPath.getList("svs:NsdocListResponse.svs:NsdocFile");
assertNotNull(files);
assertEquals(1, files.size());
verify(nsdocService, times(1)).list();
verify(nsdocService).list();
}

@Test
Expand All @@ -78,7 +79,7 @@ void get_WhenCalled_ThenContentReturned() {
var nsdocFile = xmlPath.getString("svs:NsdocResponse.svs:NsdocFile");
assertNotNull(nsdocFile);
assertEquals(result, nsdocFile);
verify(nsdocService, times(1)).get(id);
verify(nsdocService).get(id);
}

@Test
Expand All @@ -99,14 +100,14 @@ void get_WhenCalledWithUnknownFile_Then404Returned() {
.response();

var xmlPath = response.xmlPath()
.using(xmlPathConfig().declaredNamespace("commons", JaxrsConstants.COMPAS_COMMONS_V1_NS_URI));
.using(xmlPathConfig().declaredNamespace("commons", COMPAS_COMMONS_V1_NS_URI));
var messages = xmlPath.getList("commons:ErrorResponse.commons:ErrorMessage");
assertNotNull(messages);
assertEquals(1, messages.size());

var code = xmlPath.getString("commons:ErrorResponse.commons:ErrorMessage.commons:Code");
assertEquals(SclValidatorErrorCode.NSDOC_FILE_NOT_FOUND, code);

verify(nsdocService, times(1)).get(id);
verify(nsdocService).get(id);
}
}
Loading

0 comments on commit ab314d7

Please sign in to comment.