Skip to content

Commit

Permalink
Verify devService integration
Browse files Browse the repository at this point in the history
* Keycloak
* Kafka/RedPanda
* amqp
* Postgresql
* Mysql
* Mariadb
* Mssql
  • Loading branch information
pablo gonzalez granados authored and Sgitario committed Aug 23, 2021
1 parent 4bb8e1d commit 62991b7
Show file tree
Hide file tree
Showing 21 changed files with 696 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.quarkus.ts.messaging.amqpreactive;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import com.github.dockerjava.api.model.Image;

import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.DevModeQuarkusApplication;

@Tag("QUARKUS-959")
@QuarkusScenario
public class DevModeAmqpDevServiceUserExperienceIT {

private static final String AMQP_VERSION = "0.1.3";
private static final String AMQP_IMAGE = "quay.io/artemiscloud/activemq-artemis-broker";

/**
* AMQP must be started using DEV services when running in DEV mode
*/
@DevModeQuarkusApplication
static RestService app = new RestService()
.withProperty("quarkus.amqp.devservices.image-name", String.format("%s:%s", AMQP_IMAGE, AMQP_VERSION))
.onPreStart(s -> DockerUtils.removeImage(AMQP_IMAGE, AMQP_VERSION));

@Test
public void verifyIfUserIsInformedAboutAmqpDevServicePulling() {
app.logs().assertContains("Pulling docker image: quay.io/artemiscloud/activemq-artemis-broker");
app.logs().assertContains("Please be patient; this may take some time but only needs to be done once");
app.logs().assertContains("Starting to pull image");
app.logs().assertContains("Dev Services for AMQP started");
}

@Test
public void verifyAmqpImage() {
Image postgresImg = DockerUtils.getImage(AMQP_IMAGE, AMQP_VERSION);
Assertions.assertFalse(postgresImg.getId().isEmpty(), String.format("%s:%s not found. " +
"Notice that user set his own custom image by 'quarkus.keycloak.devservices.image-name' property",
AMQP_IMAGE, AMQP_VERSION));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.quarkus.ts.messaging.amqpreactive;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.DevModeQuarkusApplication;

@Tag("QUARKUS-959")
@QuarkusScenario
public class DevModeAmqpIT extends BaseAmqpIT {

Expand All @@ -12,4 +16,9 @@ public class DevModeAmqpIT extends BaseAmqpIT {
*/
@DevModeQuarkusApplication
static RestService app = new RestService();

@Test
public void amqpContainerShouldBeStarted() {
app.logs().assertContains("Creating container for image: quay.io/artemiscloud/activemq-artemis-broker");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.quarkus.ts.messaging.amqpreactive;

import java.util.List;
import java.util.Optional;

import org.testcontainers.DockerClientFactory;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.model.Image;

// TODO this DockerUtils must be removed once this changes will be released
// https://github.com/quarkus-qe/quarkus-test-framework/blob/main/quarkus-test-images/src/main/java/io/quarkus/test/utils/DockerUtils.java
public class DockerUtils {

private static final DockerClient DOCKER_CLIENT = DockerClientFactory.instance().client();;

/**
* Returns true if docker images contains expectedVersion.
*
* @param image docker images
* @param expectedVersion expected docker image version
*/
public static boolean isVersion(Image image, String expectedVersion) {
boolean exist = false;
String[] tags = Optional.ofNullable(image.getRepoTags()).orElse(new String[] {});
for (String tag : tags) {
if (tag.contains(expectedVersion)) {
exist = true;
break;
}
}

return exist;
}

/**
* Returns true if docker image is removed.
*
* @param name docker image name
* @param version docker image version
*/
public static boolean removeImage(String name, String version) {
boolean removed = false;
Image image = getImage(name, version);
if (isVersion(image, version)) {
String id = image.getId().substring(image.getId().lastIndexOf(":") + 1);
DOCKER_CLIENT.removeImageCmd(id).withForce(true).exec();
removed = true;
}
return removed;
}

/**
* Returns an image based on the provided image name and version. If no image is found then a default empty image.
* is returned
*
* @param name docker image name
* @param version docker image version
*/
public static Image getImage(String name, String version) {
Image result = new Image();
List<Image> images = DOCKER_CLIENT.listImagesCmd().withImageNameFilter(name).exec();
for (Image image : images) {
if (isVersion(image, version)) {
result = image;
break;
}
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.quarkus.ts.messaging.kafka;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.DevModeQuarkusApplication;

@Tag("QUARKUS-1026")
@Tag("QUARKUS-959")
@QuarkusScenario
public class DevModeKafkaStreamIT extends BaseKafkaStreamTest {

Expand All @@ -21,4 +23,9 @@ public class DevModeKafkaStreamIT extends BaseKafkaStreamTest {
protected String getAppUrl() {
return app.getHost() + ":" + app.getPort();
}

@Test
public void kafkaContainerShouldBeStarted() {
app.logs().assertContains("Creating container for image: vectorized/redpanda");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.quarkus.ts.messaging.kafka;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import com.github.dockerjava.api.model.Image;

import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.DevModeQuarkusApplication;

@Tag("QUARKUS-959")
@QuarkusScenario
public class DevModeRedPandaDevServiceUserExperienceIT {

private static final String RED_PANDA_VERSION = "latest";
private static final String RED_PANDA_IMAGE = "vectorized/redpanda";

@DevModeQuarkusApplication
static RestService app = new RestService()
.withProperty("quarkus.kafka.devservices.enabled", Boolean.TRUE.toString())
.withProperty("quarkus.kafka.devservices.image-name", String.format("%s:%s", RED_PANDA_IMAGE, RED_PANDA_VERSION))
.onPreStart(s -> DockerUtils.removeImage(RED_PANDA_IMAGE, RED_PANDA_VERSION));

@Test
public void verifyIfUserIsInformedAboutRedPandaDevServicePulling() {
app.logs().assertContains("Pulling docker image: vectorized/redpanda");
app.logs().assertContains("Please be patient; this may take some time but only needs to be done once");
app.logs().assertContains("Starting to pull image");
app.logs().assertContains("Dev Services for Kafka started");
}

@Test
public void verifyRedPandaImage() {
Image postgresImg = DockerUtils.getImage(RED_PANDA_IMAGE, RED_PANDA_VERSION);
Assertions.assertFalse(postgresImg.getId().isEmpty(), String.format("%s:%s not found. " +
"Notice that user set his own custom image by 'quarkus.datasource.devservices.image-name' property",
RED_PANDA_IMAGE, RED_PANDA_VERSION));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.quarkus.ts.messaging.kafka;

import java.util.List;
import java.util.Optional;

import org.testcontainers.DockerClientFactory;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.model.Image;

// TODO this DockerUtils must be removed once this changes will be released
// https://github.com/quarkus-qe/quarkus-test-framework/blob/main/quarkus-test-images/src/main/java/io/quarkus/test/utils/DockerUtils.java
public class DockerUtils {

private static final DockerClient DOCKER_CLIENT = DockerClientFactory.instance().client();;

/**
* Returns true if docker images contains expectedVersion.
*
* @param image docker images
* @param expectedVersion expected docker image version
*/
public static boolean isVersion(Image image, String expectedVersion) {
boolean exist = false;
String[] tags = Optional.ofNullable(image.getRepoTags()).orElse(new String[] {});
for (String tag : tags) {
if (tag.contains(expectedVersion)) {
exist = true;
break;
}
}

return exist;
}

/**
* Returns true if docker image is removed.
*
* @param name docker image name
* @param version docker image version
*/
public static boolean removeImage(String name, String version) {
boolean removed = false;
Image image = getImage(name, version);
if (isVersion(image, version)) {
String id = image.getId().substring(image.getId().lastIndexOf(":") + 1);
DOCKER_CLIENT.removeImageCmd(id).withForce(true).exec();
removed = true;
}
return removed;
}

/**
* Returns an image based on the provided image name and version. If no image is found then a default empty image.
* is returned
*
* @param name docker image name
* @param version docker image version
*/
public static Image getImage(String name, String version) {
Image result = new Image();
List<Image> images = DOCKER_CLIENT.listImagesCmd().withImageNameFilter(name).exec();
for (Image image : images) {
if (isVersion(image, version)) {
result = image;
break;
}
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkus.ts.security;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import com.github.dockerjava.api.model.Image;

import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.scenarios.annotations.DisabledOnNative;
import io.quarkus.test.services.DevModeQuarkusApplication;

@Tag("QUARKUS-959")
@QuarkusScenario
public class DevModeKeycloakDevServiceUserExperienceIT {

private static final String KEYCLOAK_VERSION = "13.0.1";
private static final String KEYCLOAK_IMAGE = "quay.io/keycloak/keycloak";

/**
* Keycloak must be started using DEV services when running in DEV mode
*/
@DevModeQuarkusApplication
static RestService app = new RestService()
.withProperty("quarkus.keycloak.devservices.image-name", String.format("%s:%s", KEYCLOAK_IMAGE, KEYCLOAK_VERSION))
.onPreStart(s -> DockerUtils.removeImage(KEYCLOAK_IMAGE, KEYCLOAK_VERSION));

@Test
public void verifyIfUserIsInformedAboutKeycloakDevServicePulling() {
app.logs().assertContains("Pulling docker image: quay.io/keycloak/keycloak");
app.logs().assertContains("Please be patient; this may take some time but only needs to be done once");
app.logs().assertContains("Starting to pull image");
// TODO https://github.com/quarkusio/quarkus/issues/19485
//app.logs().assertContains("Dev Services for Keycloak started");
}

@Test
public void verifyKeycloakImage() {
Image postgresImg = DockerUtils.getImage(KEYCLOAK_IMAGE, KEYCLOAK_VERSION);
Assertions.assertFalse(postgresImg.getId().isEmpty(), String.format("%s:%s not found. " +
"Notice that user set his own custom image by 'quarkus.keycloak.devservices.image-name' property",
KEYCLOAK_IMAGE, KEYCLOAK_VERSION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.DevModeQuarkusApplication;

@Tag("QUARKUS-959")
@Tag("QUARKUS-1026")
@QuarkusScenario
public class DevModeOidcSecurityIT {
Expand Down
Loading

0 comments on commit 62991b7

Please sign in to comment.