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: NotNull check for a type param in DeplomentsResource + test…
… expansion * Add more tests for Deployments resources + native tests
- Loading branch information
Showing
7 changed files
with
547 additions
and
97 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
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
package io.kaoto.backend.api.resource.support; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.NoSuchFileException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
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) { | ||
try { | ||
// 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); | ||
for (int i = 0; i < 15; i++) { | ||
String log = readFile(quarkusNativeLog); | ||
if (log.contains(String.format("Catalog class %s_Subclass warmed up in", catalogClassName))) { | ||
break; | ||
} else { | ||
if (i == 14) { | ||
Assertions.fail(String.format("Catalog %s has not been warmed up in time. Check log file %s", | ||
catalogClassName, quarkusNativeLog)); | ||
} | ||
Thread.sleep(2000); | ||
} | ||
} | ||
} catch (NoSuchFileException e) { | ||
Assertions.fail("The quarkus.log file doesn't exist in the api/target! This can happen when integration" + | ||
" tests are executing against a running application instead of running with tests together." + | ||
" Setting custom quarkus log path is not implemented yet!"); | ||
} catch (InterruptedException | IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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 DeploymentsResourcesTestAbstract { | ||
|
||
@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 DeploymentsResourcesTestAbstract { | ||
|
||
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.