Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ All validation rules have been updated to comply with the SysMLv2 2025-04 specif
=== Improvements

- https://github.com/eclipse-syson/syson/issues/1384[#1384] [metamodel] Align metamodel to SysMLv2 2025-04 specification released on April 2025(see https://www.omg.org/spec/SysML/ for more details) and KerML 2025-04 specification released on April 2024(see https://www.omg.org/spec/KerML/ for more details).
- https://github.com/eclipse-syson/syson/issues/1448[#1448] [syson] Exclude referenced libraries from validation

=== New features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@
package org.eclipse.syson.application.libraries.imports;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;

import java.time.Duration;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;

import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.sirius.components.collaborative.validation.dto.ValidationEventInput;
import org.eclipse.sirius.components.collaborative.validation.dto.ValidationRefreshedEventPayload;
import org.eclipse.sirius.components.core.api.IEditingContextSearchService;
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext;
import org.eclipse.sirius.web.application.library.dto.ImportLibrariesInput;
import org.eclipse.sirius.web.application.library.services.LibraryMetadataAdapter;
import org.eclipse.sirius.web.domain.boundedcontexts.library.Library;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticData;
import org.eclipse.sirius.web.tests.graphql.ValidationEventSubscriptionRunner;
import org.eclipse.syson.application.libraries.SysONLibraryImportTestServer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -40,6 +48,8 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import reactor.test.StepVerifier;

/**
* {@link SysONLibraryImportTests} implementation for library import-by-reference.
*
Expand All @@ -54,23 +64,20 @@ public class SysONLibraryImportByReferenceTests extends SysONLibraryImportTests
@Autowired
private IEditingContextSearchService editingContextSearchService;

@Autowired
private ValidationEventSubscriptionRunner validationEventSubscriptionRunner;

@Override
@BeforeEach
public void initializeServerState() {
super.initializeServerState();

final ImportLibrariesInput importLibrariesInput = new ImportLibrariesInput(
UUID.randomUUID(),
super.projectEditingContext.getId(),
"import",
List.of(this.loadMyLibraryV1().getId().toString()));
this.projectEditingContextEventProcessor.handle(importLibrariesInput);
}

@Test
@DisplayName("The metadata of the imported library have not changed")
@SysONLibraryImportTestServer
public void testLibraryMetadataHaveNotChanged(CapturedOutput capturedOutput) {
this.importLibraryV1();
final Library myLibraryV1 = this.loadMyLibraryV1();
assertThat(myLibraryV1.getLastModifiedOn()).isEqualTo(this.myLibraryV1LastModifiedInstantBefore);
}
Expand All @@ -79,6 +86,7 @@ public void testLibraryMetadataHaveNotChanged(CapturedOutput capturedOutput) {
@DisplayName("The semantic data of the imported Library have not changed")
@SysONLibraryImportTestServer
public void testLibrarySemanticDataHaveNotChanged(CapturedOutput capturedOutput) {
this.importLibraryV1();
final SemanticData myLibraryV1SemanticData = this.loadMyLibraryV1SemanticData();
assertThat(myLibraryV1SemanticData.getLastModifiedOn()).isEqualTo(this.myLibraryV1SemanticDataLastModifiedInstantBefore);
}
Expand All @@ -87,6 +95,7 @@ public void testLibrarySemanticDataHaveNotChanged(CapturedOutput capturedOutput)
@DisplayName("The dependencies of the project importing the library have changed")
@SysONLibraryImportTestServer
public void testImportingProjectDependenciesHaveChanged(CapturedOutput capturedOutput) {
this.importLibraryV1();
final SemanticData projectSemanticData = this.loadProjectSemanticData();
assertThat(projectSemanticData.getDependencies()).hasSize(1);
assertThat(projectSemanticData.getDependencies().get(0).dependencySemanticDataId().getId().toString()).isEqualTo(this.loadMyLibraryV1SemanticData().getId().toString());
Expand All @@ -96,6 +105,7 @@ public void testImportingProjectDependenciesHaveChanged(CapturedOutput capturedO
@DisplayName("The project importing the libraries now has a local copy of the library documents")
@SysONLibraryImportTestServer
public void testImportingProjectSemanticDataHaveChanged(CapturedOutput capturedOutput) {
this.importLibraryV1();
final ResourceSet projectResourceSet = ((IEMFEditingContext) this.projectEditingContext).getDomain().getResourceSet();
final SemanticData myLibraryV1SemanticData = this.loadMyLibraryV1SemanticData();
final List<Resource> libraryResources = ((IEMFEditingContext) this.editingContextSearchService.findById(myLibraryV1SemanticData.getId().toString())
Expand Down Expand Up @@ -147,4 +157,53 @@ public void testImportingProjectSemanticDataHaveChanged(CapturedOutput capturedO
.hasSameElementsAs(libraryCopiedResource.getContents());
}
}

@Test
@DisplayName("The validation view of the project displays the same amount of validation rules after the import")
@SysONLibraryImportTestServer
public void testValidationAfterImport() {
ValidationEventInput validationEventInput = new ValidationEventInput(UUID.randomUUID(), this.projectEditingContext.getId(), "validation://");
var validationFlux = this.validationEventSubscriptionRunner.run(validationEventInput);

AtomicReference<Integer> diagnosticCount = new AtomicReference<>(0);

Consumer<Object> validationContentConsumer = payload -> Optional.of(payload)
.filter(ValidationRefreshedEventPayload.class::isInstance)
.map(ValidationRefreshedEventPayload.class::cast)
.map(ValidationRefreshedEventPayload::validation)
.ifPresentOrElse(validation -> {
assertThat(validation).isNotNull();
diagnosticCount.set(validation.getDiagnostics().size());
}, () -> fail("Missing validation"));

Runnable importLibrary = () -> {
this.importLibraryV1();
};

Consumer<Object> validationUpdatedContentConsumer = payload -> Optional.of(payload)
.filter(ValidationRefreshedEventPayload.class::isInstance)
.map(ValidationRefreshedEventPayload.class::cast)
.map(ValidationRefreshedEventPayload::validation)
.ifPresentOrElse(validation -> {
assertThat(validation).isNotNull();
assertThat(validation.getDiagnostics().size()).isEqualTo(diagnosticCount.get());
}, () -> fail("Missing validation"));

StepVerifier.create(validationFlux)
.consumeNextWith(validationContentConsumer)
.then(importLibrary)
.consumeNextWith(validationUpdatedContentConsumer)
.thenCancel()
.verify(Duration.ofSeconds(10));

}

private void importLibraryV1() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this away from the @BeforeEach because I needed to check stuff before the import.
In any case, I think this class should be reworked because it doesn't rely on the GraphQL APIs like the other integration tests (see for example line 207 projectEditingContextEventProcessor.handle which hooks into the event processor instead of a query runner).

This is not the scope of this PR though, so I adapted the code to fit my new test case.

final ImportLibrariesInput importLibrariesInput = new ImportLibrariesInput(
UUID.randomUUID(),
super.projectEditingContext.getId(),
"import",
List.of(this.loadMyLibraryV1().getId().toString()));
this.projectEditingContextEventProcessor.handle(importLibrariesInput);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IValidationService;
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext;
import org.eclipse.sirius.web.application.library.services.LibraryMetadataAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -69,7 +70,10 @@ private List<Object> validate(IEMFEditingContext editingContext) {
var diagnostician = this.getNewDiagnostician();

var objects = domain.getResourceSet().getResources().stream()
.filter(r -> r.getURI() != null && r.getURI().toString().startsWith(IEMFEditingContext.RESOURCE_SCHEME))
.filter(r -> r.getURI() != null
&& r.getURI().toString().startsWith(IEMFEditingContext.RESOURCE_SCHEME)
// Do not validate referenced libraries: it is the responsibility of the library project
&& r.eAdapters().stream().noneMatch(LibraryMetadataAdapter.class::isInstance))
.map(Resource::getContents)
.flatMap(Collection::stream)
.map(eObject -> diagnostician.validate(eObject, options))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ The deletions are:
All standard libraries have been updated to comply with the {sysmlv2} 2025-04 specification.
All validation rules have been updated to comply with the {sysmlv2} 2025-04 specification.

- Exclude referenced libraries from validation
Referenced libraries are not validated anymore since users can't fix them in their project.
It is the responsibility of the library owner to fix the validation issues in the project that contains the library.

== Dependency update

- Switch to https://github.com/spring-projects/spring-boot/releases/tag/v3.5.0[Spring Boot 3.5.0]
Expand Down
Loading