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.
fix/test: null check for a type param in Deploment + test expansion
* Add more tests for Deployments resources + native tests
- Loading branch information
Showing
10 changed files
with
935 additions
and
454 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
42 changes: 42 additions & 0 deletions
42
api/src/test/java/io/kaoto/backend/api/resource/support/NativeHelper.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,42 @@ | ||
package io.kaoto.backend.api.resource.support; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.awaitility.Durations; | ||
import org.jboss.logging.Logger; | ||
|
||
import java.nio.file.NoSuchFileException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.time.Duration; | ||
|
||
import static io.quarkus.bootstrap.util.IoUtils.readFile; | ||
|
||
/** | ||
* Functions that help native testing to use the same functionality as JVM testing does with injection | ||
*/ | ||
public class NativeHelper { | ||
|
||
private static final Logger log = Logger.getLogger(NativeHelper.class); | ||
|
||
|
||
public static void waitForWarmUpCatalog(String catalogClassName) { | ||
// when quarkus run native image before native tests, they set path to log to api/target/quarkus.log | ||
// and it cannot be overridden | ||
Path quarkusNativeLog = Paths.get("target", "quarkus.log"); | ||
log.info("Using Quarkus log file from " + quarkusNativeLog); | ||
Awaitility.await() | ||
.timeout(Duration.ofSeconds(20)) | ||
.pollDelay(Durations.ONE_SECOND) | ||
.dontCatchUncaughtExceptions() | ||
.until(() -> { | ||
try { | ||
return readFile(quarkusNativeLog).contains( | ||
String.format("Catalog class %s_Subclass warmed up in", catalogClassName)); | ||
} catch (NoSuchFileException e) { | ||
throw new IllegalStateException("The quarkus.log file doesn't exist in the api/target! " + | ||
"This can happen when integration tests are executing against a running application. " + | ||
"Usage NativeHelper in remote native testing is not implemented yet!"); | ||
} | ||
}); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceIT.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,15 @@ | ||
package io.kaoto.backend.api.resource.v1; | ||
|
||
import io.kaoto.backend.api.metadata.catalog.StepCatalog; | ||
import io.kaoto.backend.api.resource.support.NativeHelper; | ||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
|
||
@QuarkusIntegrationTest | ||
public class DeploymentsResourceIT extends DeploymentsResourceTestAbstract { | ||
|
||
@Override | ||
protected void waitForWarmUpCatalog() { | ||
NativeHelper.waitForWarmUpCatalog(StepCatalog.class.getCanonicalName()); | ||
} | ||
} |
99 changes: 6 additions & 93 deletions
99
api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceTest.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,110 +1,23 @@ | ||
package io.kaoto.backend.api.resource.v1; | ||
|
||
import io.kaoto.backend.api.metadata.catalog.StepCatalog; | ||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.core.Response; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
|
||
@QuarkusTest | ||
@WithKubernetesTestServer | ||
@TestHTTPEndpoint(DeploymentsResource.class) | ||
class DeploymentsResourceTest { | ||
class DeploymentsResourceTest extends DeploymentsResourceTestAbstract { | ||
|
||
private StepCatalog catalog; | ||
|
||
@Test | ||
void test() throws URISyntaxException, IOException { | ||
|
||
catalog.waitForWarmUp().join(); | ||
|
||
var res = given() | ||
.when() | ||
.contentType("application/json") | ||
.get() | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
assertEquals("[]", res.extract().response().asString()); | ||
|
||
|
||
String yamlBinding = Files.readString(Path.of( | ||
DeploymentsResourceTest.class.getResource( | ||
"../twitter-search-source-binding.yaml") | ||
.toURI())); | ||
final var name = "integration-4"; | ||
|
||
given() | ||
.when() | ||
.get("/{name}", name) | ||
.then() | ||
.statusCode(Response.Status.NOT_FOUND.getStatusCode()); | ||
|
||
given() | ||
.when() | ||
.contentType("application/json") | ||
.delete("/{name}", name) | ||
.then() | ||
.statusCode(Response.Status.NOT_FOUND.getStatusCode()); | ||
|
||
given() | ||
.when().body(yamlBinding) | ||
.contentType("text/yaml") | ||
.post("/{name}", "Updated integration") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
|
||
res = given() | ||
.when() | ||
.contentType("application/json") | ||
.get() | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
assertNotEquals("[]", res.extract().response().asString()); | ||
|
||
res = given() | ||
.when() | ||
.get("/{name}", name) | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
var yaml = res.extract().response().asString(); | ||
assertNotNull(yaml); | ||
assertTrue(yaml.contains("kind: KameletBinding")); | ||
assertTrue(yaml.contains("name: twitter-search-source")); | ||
assertTrue(yaml.contains("name: aws-translate-action")); | ||
|
||
res = given() | ||
.when() | ||
.contentType("application/json") | ||
.delete("/{name}", name) | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
assertTrue(Boolean.valueOf(res.extract().response().asString())); | ||
|
||
res = given() | ||
.when() | ||
.contentType("application/json") | ||
.get() | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
assertEquals("[]", res.extract().response().asString()); | ||
} | ||
|
||
@Inject | ||
public void setCatalog(final StepCatalog catalog) { | ||
this.catalog = catalog; | ||
} | ||
|
||
@Override | ||
protected void waitForWarmUpCatalog() { | ||
catalog.waitForWarmUp().join(); | ||
} | ||
} |
Oops, something went wrong.