This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Extend and refactor StepResourceTest
To be able to use all tests in native mode
- Loading branch information
Showing
3 changed files
with
436 additions
and
162 deletions.
There are no files selected for viewing
56 changes: 15 additions & 41 deletions
56
api/src/test/java/io/kaoto/backend/api/resource/v1/StepResourceIT.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 |
---|---|---|
@@ -1,49 +1,23 @@ | ||
package io.kaoto.backend.api.resource.v1; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.kaoto.backend.model.step.Step; | ||
import io.kaoto.backend.api.metadata.catalog.StepCatalog; | ||
import io.kaoto.backend.api.resource.support.NativeHelper; | ||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import io.restassured.RestAssured; | ||
import io.restassured.response.ValidatableResponse; | ||
import org.assertj.core.api.Condition; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@QuarkusIntegrationTest | ||
class StepResourceIT { | ||
@Test | ||
void checkCatalogLoaded() throws Exception { | ||
ValidatableResponse response = RestAssured.given().get("/v1/steps").then().statusCode(200); | ||
|
||
String json = response.extract().body().asString(); | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
Step[] steps = objectMapper.readValue(json, Step[].class); | ||
assertThat(steps).isNotEmpty(); | ||
Condition<Step> weHaveCamelConnectors = | ||
new Condition<>(value -> value.getKind().equalsIgnoreCase("Camel-Connector"), | ||
"We have camel connectors"); | ||
Condition<Step> weHaveKamelets = | ||
new Condition<>(value -> value.getKind().equalsIgnoreCase("Kamelet"), | ||
"We have kamelets."); | ||
Condition<Step> weHaveEIPs = | ||
new Condition<>(value -> value.getKind().equalsIgnoreCase("EIP"), | ||
"We have EIPs."); | ||
assertThat(steps) | ||
.haveAtLeast(10, weHaveCamelConnectors) | ||
.haveAtLeast(10, weHaveKamelets) | ||
.haveAtLeast(10, weHaveEIPs); | ||
} | ||
class StepResourceIT extends StepResourceTestAbstract { | ||
|
||
@Test | ||
void checkAllRequiredPropertiesInitialized() throws Exception { | ||
ValidatableResponse response = RestAssured.given().get("/v1/steps").then().statusCode(200); | ||
|
||
String json = response.extract().body().asString(); | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
Step[] steps = objectMapper.readValue(json, Step[].class); | ||
@Override | ||
protected void waitForWarmUpCatalog() { | ||
NativeHelper.waitForWarmUpCatalog(StepCatalog.class.getCanonicalName()); | ||
} | ||
|
||
assertThat(steps) | ||
.allMatch(step -> step.getRequired() != null); | ||
@Override | ||
protected int numberOfSteps() { | ||
// TODO: it will be fine to make this number dynamically via NativeHelper somehow (get repos from | ||
// application.properties, use parsers etc.), but without using @Inject, not that easy | ||
// set manually for now, | ||
// to be sure that all steps which are available during JVM testing is also available in Native testing | ||
return 1122; | ||
} | ||
} | ||
} |
131 changes: 10 additions & 121 deletions
131
api/src/test/java/io/kaoto/backend/api/resource/v1/StepResourceTest.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 |
---|---|---|
@@ -1,136 +1,25 @@ | ||
package io.kaoto.backend.api.resource.v1; | ||
|
||
import io.kaoto.backend.api.metadata.catalog.StepCatalog; | ||
import io.kaoto.backend.model.step.Step; | ||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Timeout; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import jakarta.inject.Inject; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(StepResource.class) | ||
class StepResourceTest { | ||
|
||
public static final String INFINISPAN_SOURCE = "infinispan-source"; | ||
private StepResource stepResource; | ||
private StepCatalog catalog; | ||
|
||
@Inject | ||
public void setStepCatalog(final StepCatalog catalog) { | ||
this.catalog = catalog; | ||
} | ||
|
||
@Inject | ||
public void setStepResource(final StepResource stepResource) { | ||
this.stepResource = stepResource; | ||
} | ||
|
||
@BeforeEach | ||
void ensureCatalog() { | ||
class StepResourceTest extends StepResourceTestAbstract { | ||
@Override | ||
protected void waitForWarmUpCatalog() { | ||
catalog.waitForWarmUp().join(); | ||
} | ||
|
||
@Test | ||
void stepById() { | ||
Step s = stepResource.stepById(INFINISPAN_SOURCE + "-START"); | ||
Assertions.assertNotNull(s); | ||
Assertions.assertEquals(s.getName() + "-" + s.getType(), s.getId()); | ||
} | ||
|
||
@Test | ||
void stepsByName() { | ||
Collection<Step> steps = stepResource.stepsByName(INFINISPAN_SOURCE); | ||
for (Step s : steps) { | ||
Assertions.assertNotNull(s); | ||
Assertions.assertEquals(INFINISPAN_SOURCE, s.getName()); | ||
Assertions.assertEquals(s.getName() + "-" + s.getType(), s.getId()); | ||
} | ||
} | ||
|
||
@Test | ||
@Timeout(100) | ||
void speedKamelet() { | ||
stepResource.all("KameletBinding", null, null, null, null, null, null); | ||
@Override | ||
protected int numberOfSteps() { | ||
return catalog.getReadOnlyCatalog().getAll().size(); | ||
} | ||
|
||
@Test | ||
@Timeout(100) | ||
void speedKameletAndBinding() { | ||
stepResource.all("KameletBinding,Kamelet", null, null, null, null, null, null); | ||
} | ||
@Test | ||
@Timeout(100) | ||
void speedKameletAndBindingEnd() { | ||
stepResource.all("KameletBinding,Kamelet", Step.END, null, null, null, null, null); | ||
} | ||
@Test | ||
@Timeout(100) | ||
void speedKameletBindingMiddle() { | ||
stepResource.all("KameletBinding", Step.MIDDLE, null, null, null, null, null); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(longs = {10l, 25l, 42l}) | ||
@Timeout(100) | ||
void limitAndStart(long limitParameter) { | ||
Assertions.assertTrue(stepResource.all(null, null, null, null, null, null, null).size() > limitParameter); | ||
List<Step> limit = stepResource.all(null, null, null, limitParameter, null, null, null).stream().toList(); | ||
Assertions.assertEquals(limitParameter, limit.size()); | ||
|
||
Long[] startParameters = new Long[]{0l, 3l, 5l}; | ||
|
||
for (Long startParameter : startParameters) { | ||
List<Step> start = | ||
stepResource.all(null, null, null, limitParameter, startParameter, null, null).stream().toList(); | ||
Assertions.assertEquals(limitParameter, start.size()); | ||
|
||
for (int i = 0; i < startParameter; i++) { | ||
Assertions.assertEquals(limit.get((int) (startParameter + i)), start.get(i)); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
void allSteps() { | ||
Collection<Step> steps = stepResource.all(null, null, null, null, null, null, null); | ||
Assertions.assertNotNull(steps); | ||
Assertions.assertEquals( | ||
catalog.getReadOnlyCatalog().getAll().size(), | ||
steps.size()); | ||
|
||
var integrationType = "KameletBinding"; | ||
Assertions.assertNotNull(steps); | ||
Assertions.assertTrue( | ||
stepResource.all(null, integrationType, null, null, null, null, null) | ||
.stream().allMatch(s -> | ||
integrationType.equalsIgnoreCase(s.getType()))); | ||
|
||
var kind = "Kamelet"; | ||
Assertions.assertNotNull(steps); | ||
Assertions.assertTrue( | ||
stepResource.all(null, null, kind, null, null, null, null) | ||
.stream().allMatch(s -> | ||
kind.equalsIgnoreCase(s.getKind()))); | ||
var type = Step.START; | ||
Assertions.assertNotNull(steps); | ||
Assertions.assertTrue( | ||
stepResource.all(type, null, null, null, null, null, null) | ||
.stream().allMatch(s -> | ||
type.equalsIgnoreCase(s.getType()))); | ||
private StepCatalog catalog; | ||
|
||
Assertions.assertNotNull(steps); | ||
Assertions.assertTrue( | ||
stepResource.all(type, integrationType, kind, null, null, null, null) | ||
.stream().allMatch(s -> | ||
type.equalsIgnoreCase(s.getType()) | ||
&& kind.equalsIgnoreCase(s.getKind()))); | ||
@Inject | ||
public void setStepCatalog(final StepCatalog catalog) { | ||
this.catalog = catalog; | ||
} | ||
} |
Oops, something went wrong.