Skip to content

Commit bd85278

Browse files
author
Dennis Labordus
authored
Merge pull request #45 from com-pas/develop
New release
2 parents 66a091f + 4ffa16e commit bd85278

File tree

27 files changed

+1165
-20
lines changed

27 files changed

+1165
-20
lines changed

DEVELOPMENT.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,20 @@ git submodule update
3333
Importing the project is a bit harder for the SCL Validator then normal. It's caused because of the submodules that are
3434
needed from RiseClipse. These projects are Eclipse projects using Eclipse Tycho to build and Eclipse project structure.
3535

36-
A way to make everything work in IntelliJ is importing the project in the following way.
36+
The first step to make it work in IntelliJ is that an Eclipse version needs to be available on your local machine. The
37+
version we know that's working can be found [here](https://www.eclipse.org/downloads/packages/release/2019-06/r)
38+
Download (and install/unzip) Eclipse.
39+
40+
Next a way to make everything work in IntelliJ is importing the project in the following way.
3741

3842
- First step is to just import everything like it are Maven projects;
43+
- Next we need to add a Global Library in IntelliJ. Open the Module Settings and select "Global Libraries". And a new
44+
libraries and name it "ECLIPSE". Point it to the directory "<ECLIPSE_INSTALL_DIR>/plugins";
3945
- Next step is to re-import the RiseClipse Submodule as Eclipse;
40-
- In IntelliJ select "File" -> "New" -> "Module from Existing Sources...";
41-
- Select one of the RiseClipse Submodules, for instance "riseclipse-metamodel-scl2003";
42-
- Next select "Eclipse" by "Import module from External Model";
43-
- Follow the rest of the wizard, only to remember to select all subprojects that are available in the directory;
46+
- In IntelliJ select "File" -> "New" -> "Module from Existing Sources...";
47+
- Select one of the RiseClipse Submodules, for instance "riseclipse-metamodel-scl2003";
48+
- Next select "Eclipse" by "Import module from External Model";
49+
- Follow the rest of the wizard, only to remember to select all subprojects that are available in the directory;
4450

4551
Now the module should be correctly imported in IntelliJ to be used. Check the Module Settings of one of the subprojects
4652
to check if the directory "src" is a Java Source Directory, for instance the module

app/src/main/java/org/lfenergy/compas/scl/validator/rest/CompasSclValidatorConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import io.quarkus.runtime.Startup;
77
import org.lfenergy.compas.core.commons.ElementConverter;
8+
import org.lfenergy.compas.scl.validator.xsd.SclXsdValidator;
89
import org.lfenergy.compas.scl.validator.collector.CompasOclFileCollector;
910
import org.lfenergy.compas.scl.validator.collector.OclFileCollector;
1011
import org.lfenergy.compas.scl.validator.common.NsdocFinder;
@@ -37,6 +38,11 @@ public SclRiseClipseValidator createSclRiseClipseValidator(OclFileCollector oclF
3738
}
3839

3940
@Produces
41+
@ApplicationScoped
42+
public SclXsdValidator createSclXsdValidator() {
43+
return new SclXsdValidator();
44+
}
45+
4046
@Startup
4147
@ApplicationScoped
4248
public NsdocFinder createNsdocFinder(ValidatorProperties properties) {

app/src/test/java/org/lfenergy/compas/scl/validator/rest/CompasSclValidatorConfigurationTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,19 @@ void createSclRiseClipseValidator_WhenCalled_ThenObjectReturned() {
4545

4646
verify(validatorProperties, times(1)).tempDirectory();
4747
}
48+
49+
@Test
50+
void createSclXsdValidator_WhenCalled_ThenObjectReturned() {
51+
assertNotNull(new CompasSclValidatorConfiguration().createSclXsdValidator());
52+
}
53+
54+
@Test
55+
void createNsdocFinder_WhenCalled_ThenObjectReturned() {
56+
when(validatorProperties.nsdocDirectory()).thenReturn("./target/nsodcdir");
57+
58+
assertNotNull(new CompasSclValidatorConfiguration().createNsdocFinder(
59+
validatorProperties));
60+
61+
verify(validatorProperties, times(1)).nsdocDirectory();
62+
}
4863
}

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SPDX-License-Identifier: Apache-2.0
2424
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
2525
<sonarqube-plugin.version>3.2.0</sonarqube-plugin.version>
2626

27+
<compas.scl.xsd.version>0.0.4</compas.scl.xsd.version>
2728
<compas.core.version>0.8.0</compas.core.version>
2829

2930
<quarkus.platform.version>2.7.5.Final</quarkus.platform.version>
@@ -67,6 +68,12 @@ SPDX-License-Identifier: Apache-2.0
6768
<scope>import</scope>
6869
</dependency>
6970

71+
<dependency>
72+
<groupId>org.lfenergy.compas.xsd</groupId>
73+
<artifactId>compas-scl-xsd</artifactId>
74+
<version>${compas.scl.xsd.version}</version>
75+
</dependency>
76+
7077
<dependency>
7178
<groupId>org.lfenergy.compas.scl.validator</groupId>
7279
<artifactId>service</artifactId>

riseclipse/validator-riseclipse/src/main/java/org/lfenergy/compas/scl/validator/impl/SclRiseClipseValidator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.lfenergy.compas.scl.validator.util.OclUtil;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
23-
2423
import java.nio.file.Path;
2524
import java.util.ArrayList;
2625
import java.util.List;

riseclipse/validator-riseclipse/src/test/java/org/lfenergy/compas/scl/validator/impl/SclRiseClipseValidatorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import java.io.IOException;
1212
import java.nio.file.Path;
1313

14-
import static org.junit.jupiter.api.Assertions.assertEquals;
15-
import static org.junit.jupiter.api.Assertions.assertNotNull;
14+
import static org.junit.jupiter.api.Assertions.*;
1615
import static org.lfenergy.compas.scl.validator.util.TestSupportUtil.readSCL;
1716

1817
class SclRiseClipseValidatorTest {

service/src/main/java/org/lfenergy/compas/scl/validator/service/SclValidatorService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.lfenergy.compas.scl.extensions.model.SclFileType;
77
import org.lfenergy.compas.scl.validator.SclValidator;
8+
import org.lfenergy.compas.scl.validator.xsd.SclXsdValidator;
89
import org.lfenergy.compas.scl.validator.model.ValidationError;
910

1011
import javax.enterprise.context.ApplicationScoped;
@@ -14,13 +15,21 @@
1415
@ApplicationScoped
1516
public class SclValidatorService {
1617
private final SclValidator validator;
18+
private final SclXsdValidator xsdValidator;
1719

1820
@Inject
19-
public SclValidatorService(SclValidator validator) {
21+
public SclValidatorService(SclValidator validator, SclXsdValidator xsdValidator) {
2022
this.validator = validator;
23+
this.xsdValidator = xsdValidator;
2124
}
2225

2326
public List<ValidationError> validate(SclFileType type, String sclData) {
24-
return validator.validate(type, sclData);
27+
var errors = xsdValidator.validate(sclData);
28+
29+
if (errors.isEmpty()) {
30+
errors = validator.validate(type, sclData);
31+
}
32+
33+
return errors;
2534
}
2635
}

service/src/test/java/org/lfenergy/compas/scl/validator/service/SclValidatorServiceTest.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
// SPDX-License-Identifier: Apache-2.0
44
package org.lfenergy.compas.scl.validator.service;
55

6-
import org.junit.jupiter.api.BeforeEach;
76
import org.junit.jupiter.api.Test;
87
import org.junit.jupiter.api.extension.ExtendWith;
98
import org.lfenergy.compas.scl.extensions.model.SclFileType;
109
import org.lfenergy.compas.scl.validator.SclValidator;
10+
import org.lfenergy.compas.scl.validator.xsd.SclXsdValidator;
1111
import org.lfenergy.compas.scl.validator.model.ValidationError;
12+
import org.mockito.InjectMocks;
1213
import org.mockito.Mock;
1314
import org.mockito.junit.jupiter.MockitoExtension;
1415

16+
import java.util.Collections;
1517
import java.util.List;
1618

1719
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -21,28 +23,45 @@
2123
@ExtendWith(MockitoExtension.class)
2224
class SclValidatorServiceTest {
2325

26+
@InjectMocks
2427
private SclValidatorService sclValidatorService;
2528

2629
@Mock
2730
private SclValidator sclValidator;
2831

29-
@BeforeEach
30-
void beforeEach() {
31-
sclValidatorService = new SclValidatorService(sclValidator);
32-
}
32+
@Mock
33+
private SclXsdValidator xsdValidator;
3334

3435
@Test
3536
void validate_WhenCalled_ThenExpectedListReturned() {
3637
var type = SclFileType.CID;
3738
var sclData = "Some String";
3839

3940
when(sclValidator.validate(type, sclData)).thenReturn(List.of(new ValidationError()));
41+
when(xsdValidator.validate(sclData)).thenReturn(Collections.emptyList());
4042

4143
var result = sclValidatorService.validate(type, sclData);
4244

4345
assertNotNull(result);
4446
assertEquals(1, result.size());
4547

4648
verify(sclValidator, times(1)).validate(type, sclData);
49+
verify(xsdValidator, times(1)).validate(sclData);
50+
}
51+
52+
@Test
53+
void validate_WhenXsdErrorsAreReturned_ThenSclValidatorIsNeverCalled() {
54+
var type = SclFileType.CID;
55+
var sclData = "Some String";
56+
57+
when(xsdValidator.validate(sclData)).thenReturn(List.of(new ValidationError()));
58+
59+
var result = sclValidatorService.validate(type, sclData);
60+
61+
assertNotNull(result);
62+
assertEquals(1, result.size());
63+
64+
verify(xsdValidator, times(1)).validate(sclData);
65+
verify(sclValidator, never()).validate(type, sclData);
4766
}
4867
}

validator/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ SPDX-License-Identifier: Apache-2.0
1818
<packaging>jar</packaging>
1919

2020
<dependencies>
21+
<dependency>
22+
<groupId>org.lfenergy.compas.xsd</groupId>
23+
<artifactId>compas-scl-xsd</artifactId>
24+
</dependency>
2125
<dependency>
2226
<groupId>org.lfenergy.compas.core</groupId>
2327
<artifactId>commons</artifactId>

validator/src/main/java/org/lfenergy/compas/scl/validator/exception/SclValidatorErrorCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class SclValidatorErrorCode {
1010

1111
public static final String NO_SCL_ELEMENT_FOUND_ERROR_CODE = "SVS-0001";
1212
public static final String LOADING_SCL_FILE_ERROR_CODE = "SVS-0002";
13+
public static final String LOADING_XSD_FILE_ERROR_CODE = "SVS-0003";
1314

1415
public static final String LOADING_OCL_FILES_FAILED = "SVS-1001";
1516
public static final String LOADING_CUSTOM_OCL_FILES_FAILED = "SVS-1002";
@@ -19,6 +20,7 @@ public class SclValidatorErrorCode {
1920
public static final String WRITE_TO_OCL_TEMP_FILES_FAILED = "SVS-2003";
2021
public static final String OCL_MODEL_PACKAGE_NOT_FOUND = "SVS-2005";
2122
public static final String NO_URI_PASSED = "SVS-2006";
23+
public static final String RESOURCE_RESOLVER_FAILED = "SVS-2007";
2224

2325
public static final String CALCULATING_CHECKSUM_FAILED = "SVS-3001";
2426
public static final String DETERMINING_ID_FAILED = "SVS-3002";

0 commit comments

Comments
 (0)