forked from KaotoIO/kaoto-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide native tests for Integrations resource
- it allows to have a non-regression test for KaotoIO#617 issue with expressions - extracted a single test from IntegrationsResourceTest which cannot be launch in Native mode because it is using @Inject to access internal services directly. it allows to inherit the native test class from IntegrationsResourceTest and play all of the existing tests in native part of KaotoIO#617 part of KaotoIO#437 Signed-off-by: Aurélien Pupier <[email protected]>
- Loading branch information
Showing
3 changed files
with
148 additions
and
112 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
api/src/test/java/io/kaoto/backend/api/resource/v1/IntegrationsResourceIT.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,8 @@ | ||
package io.kaoto.backend.api.resource.v1; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
class IntegrationsResourceIT extends IntegrationsResourceTest { | ||
|
||
} |
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
137 changes: 137 additions & 0 deletions
137
...test/java/io/kaoto/backend/api/resource/v1/IntegrationsResourceWithServiceAccessTest.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,137 @@ | ||
package io.kaoto.backend.api.resource.v1; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.yaml.snakeyaml.Yaml; | ||
import org.yaml.snakeyaml.constructor.Constructor; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.kaoto.backend.api.metadata.catalog.StepCatalog; | ||
import io.kaoto.backend.api.resource.v1.model.Integration; | ||
import io.kaoto.backend.api.service.deployment.generator.kamelet.KameletRepresenter; | ||
import io.kaoto.backend.api.service.language.LanguageService; | ||
import io.kaoto.backend.model.deployment.kamelet.KameletBinding; | ||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(IntegrationsResource.class) | ||
class IntegrationsResourceWithServiceAccessTest { | ||
|
||
private StepCatalog catalog; | ||
private LanguageService languageService; | ||
@Inject | ||
public void setStepCatalog(final StepCatalog catalog) { | ||
this.catalog = catalog; | ||
} | ||
|
||
@Inject | ||
public void setLanguageService(final LanguageService languageService) { | ||
this.languageService = languageService; | ||
} | ||
|
||
@BeforeEach | ||
void ensureCatalog() { | ||
catalog.waitForWarmUp().join(); | ||
} | ||
|
||
@Test | ||
void thereAndBackAgain() throws URISyntaxException, IOException { | ||
|
||
final var alldsl = languageService.getAll(); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
|
||
String yaml1 = Files.readString(Path.of( | ||
DeploymentsResourceTest.class.getResource( | ||
"../twitter-search-source-binding.yaml") | ||
.toURI())); | ||
|
||
var res = given() | ||
.when() | ||
.contentType("application/json") | ||
.body(Collections.emptyList()) | ||
.post("/dsls") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
final var dsllist = mapper.readValue(res.extract().body().asString(), List.class); | ||
assertEquals(alldsl.size(), dsllist.size()); | ||
assertTrue(alldsl.stream().allMatch(l -> dsllist.contains(l.get("name")))); | ||
|
||
//It will return a valid value even if we are useless users with the DSL | ||
given() | ||
.when() | ||
.contentType("text/yaml") | ||
.body(yaml1) | ||
.post("?dsl=SomethingWrong") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
|
||
res = given() | ||
.when() | ||
.contentType("text/yaml") | ||
.body(yaml1) | ||
.post("?dsl=KameletBinding") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
|
||
String json = res.extract().body().asString(); | ||
Integration integration = mapper.readValue(json, Integration.class); | ||
|
||
res = given() | ||
.when() | ||
.contentType("application/json") | ||
.body(Collections.emptyList()) | ||
.post("/dsls") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
final var dsllist2 = mapper.readValue(res.extract().body().asString(), List.class); | ||
assertEquals(alldsl.size(), dsllist2.size()); | ||
assertTrue(alldsl.stream().allMatch(l -> dsllist2.contains(l.get("name")))); | ||
|
||
res = given() | ||
.when() | ||
.contentType("application/json") | ||
.body(integration.getSteps()) | ||
.post("/dsls") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
var dsls = mapper.readValue(res.extract().body().asString(), List.class); | ||
assertEquals(1, dsls.size()); | ||
assertTrue(dsls.contains("KameletBinding")); | ||
|
||
res = given() | ||
.when() | ||
.contentType("application/json") | ||
.body(json) | ||
.post("?dsl=KameletBinding") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
|
||
String yaml2 = res.extract().body().asString(); | ||
|
||
Yaml yaml = new Yaml( | ||
new Constructor(KameletBinding.class), | ||
new KameletRepresenter()); | ||
KameletBinding res1 = yaml.load(yaml1); | ||
KameletBinding res2 = yaml.load(yaml2); | ||
|
||
assertEquals(res1, res2); | ||
|
||
} | ||
|
||
} |