-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4414] Return valid JSON on commit changes REST APIs
Bug: #4414 Signed-off-by: Axel RICHARD <[email protected]>
- Loading branch information
1 parent
35b3475
commit 57f012c
Showing
6 changed files
with
162 additions
and
4 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
104 changes: 104 additions & 0 deletions
104
...pplication/controllers/projects/CommitChangesNoPayloadRestControllerIntegrationTests.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,104 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 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.projects; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.web.AbstractIntegrationTests; | ||
import org.eclipse.sirius.web.data.TestIdentifiers; | ||
import org.eclipse.sirius.web.tests.data.GivenSiriusWebServer; | ||
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.boot.test.web.server.LocalServerPort; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* Integration tests of the project-data-versioning commits REST controller. | ||
* | ||
* @author arichard | ||
*/ | ||
@Transactional | ||
@SuppressWarnings("checkstyle:MultipleStringLiterals") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class CommitChangesNoPayloadRestControllerIntegrationTests extends AbstractIntegrationTests { | ||
|
||
@Autowired | ||
private IGivenInitialServerState givenInitialServerState; | ||
|
||
@LocalServerPort | ||
private String port; | ||
|
||
private String getHTTPBaseUrl() { | ||
return "http://localhost:" + this.port; | ||
} | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
this.givenInitialServerState.initialize(); | ||
} | ||
|
||
@Test | ||
@GivenSiriusWebServer | ||
@DisplayName("Given the Sirius Web REST API, when we ask for commit changes of a project, then it should return these commit changes with a null payload") | ||
public void givenSiriusWebRestAPIWhenWeAskForCommitChangesOfAProjectThenItShouldReturnTheseCommitChangesWithANullPayload() { | ||
var webTestClient = WebTestClient.bindToServer() | ||
.baseUrl(this.getHTTPBaseUrl()) | ||
.build(); | ||
|
||
var uri = String.format("/api/rest/projects/%s/commits/%s/changes", TestIdentifiers.ECORE_SAMPLE_PROJECT, TestIdentifiers.ECORE_SAMPLE_PROJECT); | ||
webTestClient | ||
.get() | ||
.uri(uri) | ||
.exchange() | ||
.expectStatus() | ||
.isOk() | ||
.expectBody() | ||
.jsonPath("$[0].@type").isEqualTo("DataVersion") | ||
.jsonPath("$[0].identity.@id").isEqualTo(TestIdentifiers.EPACKAGE_OBJECT.toString()) | ||
.jsonPath("$[0].identity.@type").isEqualTo("DataIdentity") | ||
.jsonPath("$[0].payload").isEqualTo(null) | ||
.jsonPath("$[1].@type").isEqualTo("DataVersion") | ||
.jsonPath("$[1].identity.@id").isEqualTo(TestIdentifiers.ECLASS_OBJECT.toString()) | ||
.jsonPath("$[0].identity.@type").isEqualTo("DataIdentity") | ||
.jsonPath("$[1].payload").isEqualTo(null); | ||
} | ||
|
||
|
||
@Test | ||
@GivenSiriusWebServer | ||
@DisplayName("Given the Sirius Web REST API, when we ask for a specific commit change, then it should return this commit change with a null payload") | ||
public void givenSiriusWebRestAPIWhenWeAskForASpecificCommitChangeThenItShouldReturnThisCommitChangeWithANullPayload() { | ||
var webTestClient = WebTestClient.bindToServer() | ||
.baseUrl(this.getHTTPBaseUrl()) | ||
.build(); | ||
|
||
var changeId = UUID.nameUUIDFromBytes((TestIdentifiers.ECORE_SAMPLE_PROJECT + TestIdentifiers.EPACKAGE_OBJECT).getBytes()); | ||
var uri = String.format("/api/rest/projects/%s/commits/%s/changes/%s", TestIdentifiers.ECORE_SAMPLE_PROJECT, TestIdentifiers.ECORE_SAMPLE_PROJECT, changeId); | ||
webTestClient | ||
.get() | ||
.uri(uri) | ||
.exchange() | ||
.expectStatus() | ||
.isOk() | ||
.expectBody() | ||
.jsonPath("$.@type").isEqualTo("DataVersion") | ||
.jsonPath("$.identity.@id").isEqualTo(TestIdentifiers.EPACKAGE_OBJECT.toString()) | ||
.jsonPath("$.identity.@type").isEqualTo("DataIdentity") | ||
.jsonPath("$.payload").isEqualTo(null); | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
...nd/sirius-web/src/test/java/org/eclipse/sirius/web/services/OnRestCommitPayloadTests.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,49 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 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.services; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.eclipse.sirius.web.application.configurationproperties.SiriusWebProperties; | ||
import org.springframework.boot.autoconfigure.condition.ConditionMessage; | ||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome; | ||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
/** | ||
* Custom condition used to detect that a REST Commit Payload related test is running. | ||
* | ||
* @author arichard | ||
*/ | ||
public class OnRestCommitPayloadTests extends SpringBootCondition { | ||
|
||
@Override | ||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { | ||
var message = ConditionMessage.forCondition(this.getClass().getSimpleName()).notAvailable("sirius.web.test.enabled"); | ||
ConditionOutcome outcome = ConditionOutcome.noMatch(message); | ||
|
||
var siriusWebTestEnabled = context.getEnvironment().getProperty("sirius.web.test.enabled", ""); | ||
var siriusWebTestEnabledFeatures = Arrays.stream(siriusWebTestEnabled.split(",")).map(String::trim).toList(); | ||
|
||
if (siriusWebTestEnabledFeatures.contains("*")) { | ||
message = ConditionMessage.forCondition(this.getClass().getSimpleName()).available("sirius.web.test.enabled=" + SiriusWebProperties.EVERYTHING); | ||
outcome = ConditionOutcome.match(message); | ||
} else if (siriusWebTestEnabledFeatures.contains("rest-commit-payload")) { | ||
message = ConditionMessage.forCondition(this.getClass().getSimpleName()).available("sirius.web.test.enabled=" + SiriusWebProperties.STUDIO); | ||
outcome = ConditionOutcome.match(message); | ||
} | ||
|
||
return outcome; | ||
} | ||
} |