-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3630] Restore support for the deletion of dangling representations
Bug: #3630 Signed-off-by: Stéphane Bégaudeau <[email protected]>
- Loading branch information
1 parent
b047d9e
commit 8cb6686
Showing
11 changed files
with
189 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...domain/boundedcontexts/representationdata/projections/RepresentationDataMetadataOnly.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024, 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.domain.boundedcontexts.representationdata.projections; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Projection used to retrieve only the representation metadata of the representation data. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public record RepresentationDataMetadataOnly( | ||
UUID id, | ||
String label, | ||
String kind, | ||
String targetObjectId, | ||
String descriptionId) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...ication/controllers/representations/DanglingRepresentationControllerIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.controllers.representations; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.Duration; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Predicate; | ||
|
||
import org.eclipse.sirius.components.collaborative.api.ChangeDescription; | ||
import org.eclipse.sirius.components.collaborative.api.ChangeKind; | ||
import org.eclipse.sirius.components.collaborative.portals.dto.PortalEventInput; | ||
import org.eclipse.sirius.components.collaborative.portals.dto.PortalRefreshedEventPayload; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IInput; | ||
import org.eclipse.sirius.components.core.api.IPayload; | ||
import org.eclipse.sirius.components.core.api.SuccessPayload; | ||
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; | ||
import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionInput; | ||
import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionRunner; | ||
import org.eclipse.sirius.components.portals.tests.graphql.PortalEventSubscriptionRunner; | ||
import org.eclipse.sirius.web.AbstractIntegrationTests; | ||
import org.eclipse.sirius.web.data.TestIdentifiers; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.test.context.jdbc.SqlConfig; | ||
import org.springframework.test.context.transaction.TestTransaction; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import graphql.execution.DataFetcherResult; | ||
import reactor.test.StepVerifier; | ||
|
||
/** | ||
* Used to test the proper deletion of dangling representations. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Transactional | ||
@SuppressWarnings("checkstyle:MultipleStringLiterals") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class DanglingRepresentationControllerIntegrationTests extends AbstractIntegrationTests { | ||
|
||
@Autowired | ||
private IGivenInitialServerState givenInitialServerState; | ||
|
||
@Autowired | ||
private PortalEventSubscriptionRunner portalEventSubscriptionRunner; | ||
|
||
@Autowired | ||
private ExecuteEditingContextFunctionRunner executeEditingContextFunctionRunner; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
this.givenInitialServerState.initialize(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Given a project, when we delete an object with a child representation, then the representation is deleted") | ||
@Sql(scripts = { "/scripts/initialize.sql" }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) | ||
public void givenProjectWhenWeDeleteAnObjectWithChildRepresentationThenTheRepresentationIsDeleted() { | ||
var portalEventInput = new PortalEventInput(UUID.randomUUID(), TestIdentifiers.ECORE_SAMPLE_PROJECT.toString(), TestIdentifiers.EPACKAGE_PORTAL_REPRESENTATION.toString()); | ||
var portalFlux = this.portalEventSubscriptionRunner.run(portalEventInput); | ||
|
||
Predicate<Object> portalContentMatcher = object -> Optional.of(object) | ||
.filter(DataFetcherResult.class::isInstance) | ||
.map(DataFetcherResult.class::cast) | ||
.map(DataFetcherResult::getData) | ||
.filter(PortalRefreshedEventPayload.class::isInstance) | ||
.isPresent(); | ||
|
||
Runnable deleteProjectContent = () -> { | ||
BiFunction<IEditingContext, IInput, IPayload> function = (editingContext, input) -> { | ||
if (editingContext instanceof IEMFEditingContext emfEditingContext) { | ||
emfEditingContext.getDomain().getResourceSet().getResources().forEach(resource -> resource.getContents().clear()); | ||
} | ||
return new SuccessPayload(input.id()); | ||
}; | ||
|
||
var inputId = UUID.randomUUID(); | ||
var changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, TestIdentifiers.ECORE_SAMPLE_PROJECT.toString(), () -> inputId); | ||
var input = new ExecuteEditingContextFunctionInput(inputId, TestIdentifiers.ECORE_SAMPLE_PROJECT.toString(), function, changeDescription); | ||
var payload = this.executeEditingContextFunctionRunner.execute(input).block(); | ||
|
||
assertThat(payload).isInstanceOf(SuccessPayload.class); | ||
|
||
TestTransaction.flagForCommit(); | ||
TestTransaction.end(); | ||
TestTransaction.start(); | ||
}; | ||
|
||
StepVerifier.create(portalFlux) | ||
.expectNextMatches(portalContentMatcher) | ||
.then(deleteProjectContent) | ||
.expectComplete() | ||
.verify(Duration.ofSeconds(10)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters