Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
*/
package org.eclipse.dirigible.integration.tests.ui.tests.sample;

import java.util.regex.Pattern;

import io.restassured.builder.RequestSpecBuilder;
import io.restassured.specification.RequestSpecification;

import static io.restassured.RestAssured.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalToCompressingWhiteSpace;

public class EntityDecoratorsSampleProjectIT extends SampleProjectRepositoryIT {
Expand All @@ -23,11 +26,24 @@ public class EntityDecoratorsSampleProjectIT extends SampleProjectRepositoryIT {
[{"Code2":"AF","Numeric":"004","Code3":"AFG","Id":1,"$type$":"CountryEntity","Name":"Afghanistan"},{"Code2":"AL","Numeric":"008","Code3":"ALB","Id":2,"$type$":"CountryEntity","Name":"Albania"},{"Code2":"DZ","Numeric":"012","Code3":"DZA","Id":3,"$type$":"CountryEntity","Name":"Algeria"}]
""";

/**
* The expected OpenAPI document with the instance's own version replaced by
* {@link #VERSION_PLACEHOLDER}. The served {@code info.version} is the real build version, which
* changes on every release and every development bump - so it is normalised out of BOTH sides of
* the comparison rather than pinned here. Pinning it made this test fail on both CI databases the
* first night after the version stopped being served as a literal {@code ${project.version}}
* (#6644).
*/
private static final String VERSION_PLACEHOLDER = "<version>";

private static final String OPENAPI_RESPONSE_BODY =
"""
{"openapi":"3.0.1","info":{"title":"Applications Services Open API","description":"Services Open API provided by the applications","contact":{"name":"Eclipse Dirigible","url":"https://www.dirigible.io","email":"dirigible-dev@eclipse.org"},"license":{"name":"Eclipse Public License - v 2.0","url":"https://www.eclipse.org/legal/epl-v20.html"},"version":"${project.version}"},"servers":[{"url":"/services/ts"},{"url":"/services/ts"}],"security":[],"tags":[],"paths":{"/sample-entity-decorators/CountryController.ts/":{"get":{"tags":["CountryController"],"summary":"getAll CountryController ","operationId":"getAll","parameters":[],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CountryEntity"}}}}}}}}},"components":{"schemas":{"number":{"type":"number"},"CountryEntity":{"type":"object","properties":{"Code2":{"type":"string"},"Numeric":{"type":"string"},"Code3":{"type":"string"},"Id":{"type":"number","description":"My Id"},"Name":{"type":"string","description":"My Name"}},"description":"Sample Country Entity"},"string":{"type":"string"},"any":{"type":"object"}},"responses":{},"parameters":{},"examples":{},"requestBodies":{},"headers":{},"securitySchemes":{},"links":{},"callbacks":{}}}
{"openapi":"3.0.1","info":{"title":"Applications Services Open API","description":"Services Open API provided by the applications","contact":{"name":"Eclipse Dirigible","url":"https://www.dirigible.io","email":"dirigible-dev@eclipse.org"},"license":{"name":"Eclipse Public License - v 2.0","url":"https://www.eclipse.org/legal/epl-v20.html"},"version":"<version>"},"servers":[{"url":"/services/ts"},{"url":"/services/ts"}],"security":[],"tags":[],"paths":{"/sample-entity-decorators/CountryController.ts/":{"get":{"tags":["CountryController"],"summary":"getAll CountryController ","operationId":"getAll","parameters":[],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CountryEntity"}}}}}}}}},"components":{"schemas":{"number":{"type":"number"},"CountryEntity":{"type":"object","properties":{"Code2":{"type":"string"},"Numeric":{"type":"string"},"Code3":{"type":"string"},"Id":{"type":"number","description":"My Id"},"Name":{"type":"string","description":"My Name"}},"description":"Sample Country Entity"},"string":{"type":"string"},"any":{"type":"object"}},"responses":{},"parameters":{},"examples":{},"requestBodies":{},"headers":{},"securitySchemes":{},"links":{},"callbacks":{}}}
""";

/** {@code "version":"<anything>"} inside the OpenAPI {@code info} block. */
private static final Pattern OPENAPI_VERSION = Pattern.compile("\"version\":\"[^\"]*\"");

@Override
protected void verifyProject() {
restAssuredExecutor.execute( //
Expand All @@ -45,14 +61,30 @@ protected void verifyProject() {

// TODO: documentation texts from @Document annotations are not added to the open api response. Fix
// this issue and adapt the test.
given().when()
.get("/services/openapi")
.then()
.statusCode(200)
.body(equalToCompressingWhiteSpace(OPENAPI_RESPONSE_BODY));
String openApi = given().when()
.get("/services/openapi")
.then()
.statusCode(200)
.extract()
.asString();
assertThat("the served OpenAPI document should match, ignoring the instance's own version", //
withoutVersion(openApi), equalToCompressingWhiteSpace(OPENAPI_RESPONSE_BODY));
}, 60);
}

/**
* The OpenAPI document with the instance's own {@code info.version} normalised to
* {@link #VERSION_PLACEHOLDER}, so the assertion survives every release and development version
* bump.
*
* @param openApi the served document
* @return the document with its version normalised
*/
private static String withoutVersion(String openApi) {
return OPENAPI_VERSION.matcher(openApi)
.replaceFirst("\"version\":\"" + VERSION_PLACEHOLDER + "\"");
}

@Override
protected String getRepositoryURL() {
return "https://github.com/dirigiblelabs/sample-entity-decorators.git";
Expand Down
Loading