|
10 | 10 | * Contributors: |
11 | 11 | * Obeo - initial API and implementation |
12 | 12 | *******************************************************************************/ |
13 | | -package org.eclipse.syson.application.publication; |
| 13 | +package org.eclipse.syson.application.libraries.publication; |
14 | 14 |
|
15 | 15 | import static org.assertj.core.api.Assertions.assertThat; |
16 | 16 |
|
|
39 | 39 | import org.eclipse.sirius.web.domain.boundedcontexts.library.services.api.ILibrarySearchService; |
40 | 40 | import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.Document; |
41 | 41 | import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticData; |
| 42 | +import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticDataDependency; |
42 | 43 | import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService; |
43 | 44 | import org.eclipse.sirius.web.tests.graphql.PublishLibrariesMutationRunner; |
44 | 45 | import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; |
45 | 46 | import org.eclipse.syson.AbstractIntegrationTests; |
| 47 | +import org.eclipse.syson.application.data.ProjectWithUnusedBatmobileLibraryDependencyTestProjectData; |
| 48 | +import org.eclipse.syson.application.data.ProjectWithUsedBatmobileLibraryDependencyTestProjectData; |
46 | 49 | import org.eclipse.syson.application.data.SimpleProjectElementsTestProjectData; |
| 50 | +import org.eclipse.syson.application.publication.SysONLibraryPublicationHandler; |
| 51 | +import org.eclipse.syson.application.publication.SysONLibraryPublicationListener; |
47 | 52 | import org.eclipse.syson.sysml.SysmlPackage; |
48 | 53 | import org.junit.jupiter.api.BeforeEach; |
49 | 54 | import org.junit.jupiter.api.DisplayName; |
|
59 | 64 | /** |
60 | 65 | * Integration tests for the publication of the SysML contents of a project as a library. |
61 | 66 | * |
62 | | - * @see SySONLibraryPublicationHandler |
| 67 | + * @see SysONLibraryPublicationHandler |
63 | 68 | * @see SysONLibraryPublicationListener |
64 | 69 | * @author flatombe |
65 | 70 | */ |
66 | 71 | @Transactional |
67 | 72 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
| 73 | +@SuppressWarnings("checkstyle:MultipleStringLiterals") |
68 | 74 | public class SySONLibraryPublicationTests extends AbstractIntegrationTests { |
69 | 75 |
|
70 | 76 | private static final String IMPORTED_PROJECT = "afffb8f5-3db6-4b47-b295-55a36984db2e"; |
@@ -247,4 +253,69 @@ public void givenProjectWithImportedResourceWhenLibraryIsPublishedThenLibraryDoe |
247 | 253 | .allSatisfy(document -> assertThat(document.getContent()).doesNotContain("\"source\":\"org.eclipse.syson.sysml.imported\"")); |
248 | 254 | } |
249 | 255 |
|
| 256 | + @Test |
| 257 | + @DisplayName("Given a project with an used dependency to a library, when the library is published, then the library has the same dependency") |
| 258 | + @Sql(scripts = { ProjectWithUsedBatmobileLibraryDependencyTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) |
| 259 | + @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) |
| 260 | + public void givenProjectWithUsedDependencyToLibraryWhenLibraryIsPublishedThenItHasTheSameDependency() { |
| 261 | + var input = new PublishLibrariesInput(UUID.randomUUID(), ProjectWithUsedBatmobileLibraryDependencyTestProjectData.PROJECT_ID, PUBLICATION_KIND, "1.0.0", ""); |
| 262 | + var result = this.publishLibrariesMutationRunner.run(input); |
| 263 | + String typename = JsonPath.read(result, "$.data.publishLibraries.__typename"); |
| 264 | + assertThat(typename).isEqualTo(SuccessPayload.class.getSimpleName()); |
| 265 | + TestTransaction.flagForCommit(); |
| 266 | + TestTransaction.end(); |
| 267 | + TestTransaction.start(); |
| 268 | + |
| 269 | + Optional<SemanticData> projectLibrarySemanticData = this.librarySearchService.findByNamespaceAndNameAndVersion(ProjectWithUsedBatmobileLibraryDependencyTestProjectData.PROJECT_ID, ProjectWithUsedBatmobileLibraryDependencyTestProjectData.PROJECT_NAME, "1.0.0") |
| 270 | + .map(Library::getSemanticData) |
| 271 | + .map(AggregateReference::getId) |
| 272 | + .flatMap(this.semanticDataSearchService::findById); |
| 273 | + |
| 274 | + assertThat(projectLibrarySemanticData).isPresent(); |
| 275 | + assertThat(projectLibrarySemanticData.get().getDependencies()).hasSize(1); |
| 276 | + SemanticDataDependency dependency = projectLibrarySemanticData.get().getDependencies().get(0); |
| 277 | + |
| 278 | + // Check that the dependency is in the published library. |
| 279 | + Optional<Library> dependencyLibrary = this.librarySearchService.findBySemanticData(dependency.dependencySemanticDataId()); |
| 280 | + assertThat(dependencyLibrary).isPresent(); |
| 281 | + assertThat(dependencyLibrary.get().getName()).isEqualTo("Batmobile"); |
| 282 | + |
| 283 | + // Check that the library contains a single document (its proper content). |
| 284 | + Set<Document> documents = projectLibrarySemanticData.get().getDocuments(); |
| 285 | + assertThat(documents) |
| 286 | + .hasSize(1) |
| 287 | + .allSatisfy(document -> assertThat(document.getName()).isEqualTo("SysMLv2.sysml")); |
| 288 | + } |
| 289 | + |
| 290 | + @Test |
| 291 | + @DisplayName("Given a project with an unused dependency to a library, when the library is published, then the library has no dependency") |
| 292 | + @Sql(scripts = { ProjectWithUnusedBatmobileLibraryDependencyTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) |
| 293 | + @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) |
| 294 | + public void givenProjectWithUnusedDependencyToLibraryWhenLibraryIsPublishedThenItHasNoDependency() { |
| 295 | + var input = new PublishLibrariesInput(UUID.randomUUID(), ProjectWithUnusedBatmobileLibraryDependencyTestProjectData.PROJECT_ID, PUBLICATION_KIND, "1.0.0", ""); |
| 296 | + var result = this.publishLibrariesMutationRunner.run(input); |
| 297 | + String typename = JsonPath.read(result, "$.data.publishLibraries.__typename"); |
| 298 | + assertThat(typename).isEqualTo(SuccessPayload.class.getSimpleName()); |
| 299 | + TestTransaction.flagForCommit(); |
| 300 | + TestTransaction.end(); |
| 301 | + TestTransaction.start(); |
| 302 | + |
| 303 | + Optional<SemanticData> projectLibrarySemanticData = this.librarySearchService |
| 304 | + .findByNamespaceAndNameAndVersion(ProjectWithUnusedBatmobileLibraryDependencyTestProjectData.PROJECT_ID, ProjectWithUnusedBatmobileLibraryDependencyTestProjectData.PROJECT_NAME, |
| 305 | + "1.0.0") |
| 306 | + .map(Library::getSemanticData) |
| 307 | + .map(AggregateReference::getId) |
| 308 | + .flatMap(this.semanticDataSearchService::findById); |
| 309 | + |
| 310 | + assertThat(projectLibrarySemanticData).isPresent(); |
| 311 | + // Check that there is no dependency in the published library. |
| 312 | + assertThat(projectLibrarySemanticData.get().getDependencies()).isEmpty(); |
| 313 | + |
| 314 | + // Check that the library contains a single document (its proper content). |
| 315 | + Set<Document> documents = projectLibrarySemanticData.get().getDocuments(); |
| 316 | + assertThat(documents) |
| 317 | + .hasSize(1) |
| 318 | + .allSatisfy(document -> assertThat(document.getName()).isEqualTo("SysMLv2.sysml")); |
| 319 | + |
| 320 | + } |
250 | 321 | } |
0 commit comments