Search in sources :

Example 1 with GatewayCreationData

use of com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData in project quick by bakdata.

the class GatewayControllerTest method shouldCreateGateway.

@Test
void shouldCreateGateway() throws JsonProcessingException {
    when(this.gatewayService.createGateway(isNotNull())).thenReturn(Completable.complete());
    final GatewayCreationData creationData = new GatewayCreationData(GATEWAY_NAME, 1, TAG, null);
    this.client.toBlocking().exchange(POST("/gateway", new ObjectMapper().writeValueAsString(creationData)));
    verify(this.gatewayService).createGateway(creationData);
}
Also used : GatewayCreationData(com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Example 2 with GatewayCreationData

use of com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData in project quick by bakdata.

the class GatewayResourceLoaderTest method shouldCreateGatewayConfigMap.

@Test
void shouldCreateGatewayConfigMap() {
    final GatewayCreationData gatewayCreationData = new GatewayCreationData(GATEWAY_NAME, REPLICAS, TAG, null);
    final GatewayResources gatewayResources = this.loader.forCreation(gatewayCreationData, ResourcePrefix.GATEWAY);
    final Optional<HasMetadata> hasMetadata = findResource(gatewayResources, ResourceKind.CONFIGMAP);
    assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(ConfigMap.class)).satisfies(configMap -> assertThat(configMap).extracting(ConfigMap::getData, InstanceOfAssertFactories.map(String.class, String.class)).containsOnlyKeys("schema.graphql"));
}
Also used : GatewayCreationData(com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 3 with GatewayCreationData

use of com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData in project quick by bakdata.

the class GatewayResourceLoaderTest method shouldCreateGatewayMiddleware.

@Test
void shouldCreateGatewayMiddleware() {
    final GatewayCreationData gatewayCreationData = new GatewayCreationData(GATEWAY_NAME, REPLICAS, TAG, null);
    final GatewayResources gatewayResources = this.loader.forCreation(gatewayCreationData, ResourcePrefix.GATEWAY);
    final Optional<HasMetadata> hasMetadata = findResource(gatewayResources, ResourceKind.MIDDLEWARE);
    final String expected = ResourcePrefix.GATEWAY.getPrefix() + GATEWAY_NAME;
    assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Middleware.class)).satisfies(middleware -> {
        assertThat(middleware.getMetadata().getName()).isEqualTo(expected);
        assertThat(middleware.getSpec().getStripPrefix().getPrefixes()).containsExactly("/gateway/" + GATEWAY_NAME);
    });
}
Also used : GatewayCreationData(com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 4 with GatewayCreationData

use of com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData in project quick by bakdata.

the class GatewayResourceLoaderTest method shouldCreateGatewayConfigMapWithSchema.

@Test
void shouldCreateGatewayConfigMapWithSchema() {
    final GatewayCreationData gatewayCreationData = new GatewayCreationData(GATEWAY_NAME, REPLICAS, TAG, "something");
    final GatewayResources gatewayResources = this.loader.forCreation(gatewayCreationData, ResourcePrefix.GATEWAY);
    final Optional<HasMetadata> hasMetadata = findResource(gatewayResources, ResourceKind.CONFIGMAP);
    assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(ConfigMap.class)).satisfies(configMap -> assertThat(configMap).extracting(ConfigMap::getData, InstanceOfAssertFactories.map(String.class, String.class)).containsOnlyKeys("schema.graphql").extractingByKey("schema.graphql", InstanceOfAssertFactories.STRING).containsIgnoringWhitespaces("something"));
}
Also used : GatewayCreationData(com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 5 with GatewayCreationData

use of com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData in project quick by bakdata.

the class GatewayResourceLoaderTest method shouldCreateGatewayDeployment.

@Test
void shouldCreateGatewayDeployment() {
    final GatewayCreationData gatewayCreationData = new GatewayCreationData(GATEWAY_NAME, REPLICAS, TAG, null);
    final GatewayResources gatewayResources = this.loader.forCreation(gatewayCreationData, ResourcePrefix.GATEWAY);
    final Optional<HasMetadata> hasMetadata = findResource(gatewayResources, ResourceKind.DEPLOYMENT);
    final String deploymentName = ResourcePrefix.GATEWAY.getPrefix() + GATEWAY_NAME;
    final Map<String, String> labels = Map.of("app.kubernetes.io/component", "gateway", "app.kubernetes.io/managed-by", "quick", "app.kubernetes.io/name", deploymentName);
    final Map<String, String> selectors = Map.of("app.kubernetes.io/component", "gateway", "app.kubernetes.io/name", deploymentName);
    final Map<String, String> annotations = Map.of("d9p.io/fixed-tag", "true");
    assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Deployment.class)).satisfies(deployment -> {
        final PodSpec podSpec = deployment.getSpec().getTemplate().getSpec();
        assertThat(podSpec.getContainers()).isNotNull().hasSize(1).first().hasFieldOrPropertyWithValue("image", getImage(DOCKER_REGISTRY, EXPECTED_GATEWAY_IMAGE, TAG));
        assertThat(deployment.getMetadata()).satisfies(metadata -> {
            assertThat(metadata.getName()).isEqualTo(deploymentName);
            assertThat(metadata.getLabels()).containsExactlyInAnyOrderEntriesOf(labels);
            assertThat(metadata.getAnnotations()).containsExactlyInAnyOrderEntriesOf(annotations);
        });
        assertThat(deployment.getSpec()).satisfies(spec -> {
            assertThat(spec.getReplicas()).isEqualTo(REPLICAS);
            assertThat(spec.getSelector().getMatchLabels()).containsExactlyInAnyOrderEntriesOf(selectors);
            assertThat(spec.getTemplate().getMetadata().getLabels()).containsExactlyInAnyOrderEntriesOf(labels);
        });
        assertThat(deployment.getSpec().getTemplate().getSpec().getVolumes()).hasSize(2).first().hasFieldOrPropertyWithValue("name", "log4j-config").extracting(Volume::getConfigMap).satisfies(configmap -> {
            assertThat(configmap.getName()).isEqualTo("quick-log4j");
            assertThat(configmap.getItems()).hasSize(1).first().hasFieldOrPropertyWithValue("key", "log4j2.yaml").hasFieldOrPropertyWithValue("path", "log4j2.yaml");
        });
        assertThat(deployment.getSpec().getTemplate().getSpec().getVolumes()).hasSize(2).element(1).hasFieldOrPropertyWithValue("name", String.format("%s-config-volume", deploymentName)).extracting(Volume::getConfigMap).satisfies(configmap -> assertThat(configmap.getName()).isEqualTo(String.format("%s-config", deploymentName)));
    });
}
Also used : GatewayCreationData(com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Aggregations

GatewayCreationData (com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData)13 Test (org.junit.jupiter.api.Test)12 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)11 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)7 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)7 DeploymentConfig (com.bakdata.quick.manager.config.DeploymentConfig)5 KubernetesResources (com.bakdata.quick.manager.k8s.KubernetesResources)5 GatewayClient (com.bakdata.quick.common.api.client.GatewayClient)3 GatewayService (com.bakdata.quick.manager.gateway.GatewayService)3 KubernetesGatewayService (com.bakdata.quick.manager.gateway.KubernetesGatewayService)3 GatewayResourceLoader (com.bakdata.quick.manager.gateway.resource.GatewayResourceLoader)3 GraphQLToAvroConverter (com.bakdata.quick.manager.graphql.GraphQLToAvroConverter)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)2 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)2 IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)2 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)1 TestUtil (com.bakdata.quick.manager.TestUtil)1 Middleware (com.bakdata.quick.manager.k8s.middleware.Middleware)1