Skip to content

Commit 119c48b

Browse files
author
Dennis Labordus
committed
Small refactoring to cleanup code.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent cf6ac7f commit 119c48b

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import org.eclipse.ocl.pivot.utilities.OCL;
1212
import org.eclipse.ocl.pivot.validation.ComposedEValidator;
1313
import org.eclipse.ocl.xtext.completeocl.validation.CompleteOCLEObjectValidator;
14+
import org.lfenergy.compas.scl.extensions.model.SclFileType;
1415
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
16+
import org.lfenergy.compas.scl.validator.util.OclUtil;
1517
import org.slf4j.Logger;
1618
import org.slf4j.LoggerFactory;
1719

@@ -27,10 +29,13 @@
2729
public class OclFileLoader {
2830
private static final Logger LOGGER = LoggerFactory.getLogger(OclFileLoader.class);
2931

32+
private final List<URI> oclFiles;
3033
private final Path oclTempFile;
3134
private final OCL ocl;
3235

33-
public OclFileLoader(Path tempDirectoryPath) {
36+
public OclFileLoader(Path tempDirectoryPath, List<URI> oclFiles) {
37+
this.oclFiles = oclFiles;
38+
3439
// Create an EPackage.Registry for the SclPackage.
3540
var registry = new EPackageRegistryImpl();
3641
registry.put(SclPackage.eNS_URI, SclPackage.eINSTANCE);
@@ -50,6 +55,12 @@ public OclFileLoader(Path tempDirectoryPath) {
5055
}
5156
}
5257

58+
public void loadOCLDocuments(SclFileType type) {
59+
oclFiles.stream()
60+
.filter(uri -> OclUtil.includeOnType(uri, type))
61+
.forEach(this::addOCLDocument);
62+
}
63+
5364
public void addOCLDocument(URI oclUri) {
5465
if (oclUri == null) {
5566
throw new SclValidatorException(NO_URI_PASSED, "Unable to create URI for temporary file");

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ public List<ValidationError> validate(SclFileType type, String sclData) {
5151
var validator = new ComposedEValidator(null);
5252
validatorRegistry.put(SclPackage.eINSTANCE, validator);
5353

54-
OclFileLoader oclFileLoader = new OclFileLoader(tempDirectory);
54+
OclFileLoader oclFileLoader = new OclFileLoader(tempDirectory, oclFiles);
5555
try {
5656
// Load all the OCL Files, adding them to the OCL Instance.
5757
LOGGER.info("Loading OCL Files for type '{}'.", type);
58-
oclFiles.stream()
59-
.filter(uri -> OclUtil.includeOnType(uri, type))
60-
.forEach(oclFileLoader::addOCLDocument);
58+
oclFileLoader.loadOCLDocuments(type);
6159
oclFileLoader.prepareValidator(validator);
6260

6361
// Load the SCL File as Resource ready to be processed.

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.junit.jupiter.api.BeforeEach;
1111
import org.junit.jupiter.api.Test;
1212
import org.junit.jupiter.api.extension.ExtendWith;
13+
import org.lfenergy.compas.scl.extensions.model.SclFileType;
1314
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
1415
import org.lfenergy.compas.scl.validator.util.OclUtil;
1516
import org.mockito.junit.jupiter.MockitoExtension;
@@ -18,6 +19,7 @@
1819
import java.io.IOException;
1920
import java.nio.file.Files;
2021
import java.nio.file.Path;
22+
import java.util.List;
2123

2224
import static org.junit.jupiter.api.Assertions.assertEquals;
2325
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -36,13 +38,22 @@ void setup() throws IOException {
3638

3739
var tempDirectory = "./target/data/temp";
3840
var tempDirectoryPath = Path.of(tempDirectory);
39-
loader = new OclFileLoader(tempDirectoryPath);
41+
var oclFile = findOCL("example.ocl");
42+
43+
loader = new OclFileLoader(tempDirectoryPath, List.of(oclFile));
4044
tempFile = Files.walk(tempDirectoryPath)
4145
.filter(path -> path.toString().contains(File.separator + "allConstraints"))
4246
.findFirst()
4347
.orElseThrow();
4448
}
4549

50+
@Test
51+
void loadOCLDocuments_WhenCalled_ThenFilesFromListAreLoaded() throws IOException {
52+
loader.loadOCLDocuments(SclFileType.CID);
53+
54+
assertEquals(1, Files.lines(tempFile).count());
55+
}
56+
4657
@Test
4758
void addOCLDocument_WhenCalledWithNull_ThenExceptionThrown() {
4859
var exception = assertThrows(SclValidatorException.class,

0 commit comments

Comments
 (0)