Search in sources :

Example 6 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class GatewayControllerTest method shouldCreateDefinition.

@Test
void shouldCreateDefinition() {
    when(this.gatewayService.updateSchema(anyString(), anyString())).thenReturn(Completable.complete());
    final String uri = UriBuilder.of(BASE_PATH + "/schema").expand(Collections.singletonMap("name", GATEWAY_NAME)).toString();
    assertEquals("/gateway/test-gateway/schema", uri);
    this.client.toBlocking().exchange(POST(uri, new SchemaData("type Query { test: String }")));
    verify(this.gatewayService).updateSchema(GATEWAY_NAME, "type Query { test: String }");
}
Also used : SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Example 7 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class KubernetesGatewayServiceTest method shouldUpdateConfigMap.

@Test
void shouldUpdateConfigMap() {
    this.createGateway(GATEWAY_NAME, 1, null);
    final String graphQLSchema = "type Query { find: String }";
    Mockito.when(this.gatewayClient.updateSchema(GATEWAY_NAME, new SchemaData(graphQLSchema))).thenReturn(Completable.complete());
    this.gatewayService.updateSchema(GATEWAY_NAME, graphQLSchema).blockingAwait();
    final List<ConfigMap> configMaps = this.getConfigMaps();
    assertThat(configMaps).hasSize(1).first().satisfies(configMap -> assertThat(configMap.getMetadata().getName()).isEqualTo(DEPLOYMENT_NAME + "-config")).satisfies(configMap -> assertThat(configMap.getData().get("schema.graphql")).isEqualTo(graphQLSchema));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Completable(io.reactivex.Completable) GatewayClient(com.bakdata.quick.common.api.client.GatewayClient) EnvFromSource(io.fabric8.kubernetes.api.model.EnvFromSource) GraphQLToAvroConverter(com.bakdata.quick.manager.graphql.GraphQLToAvroConverter) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) GatewayCreationData(com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData) Service(io.fabric8.kubernetes.api.model.Service) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) KubernetesResources(com.bakdata.quick.manager.k8s.KubernetesResources) BadArgumentException(com.bakdata.quick.common.exception.BadArgumentException) MiddlewareList(com.bakdata.quick.manager.k8s.middleware.MiddlewareList) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Nullable(edu.umd.cs.findbugs.annotations.Nullable) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) GatewayResourceLoader(com.bakdata.quick.manager.gateway.resource.GatewayResourceLoader) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 8 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class KafkaTopicServiceTest method shouldRegisterTopicGraphQLSchema.

@Test
void shouldRegisterTopicGraphQLSchema() {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    when(this.gatewayService.getGateway(GATEWAY_SCHEMA.getGateway())).thenReturn(Single.just(new GatewayDescription("test", 1, "latest")));
    when(this.gatewayClient.getWriteSchema(anyString(), anyString())).thenReturn(Single.just(new SchemaData(SCHEMA)));
    final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, GATEWAY_SCHEMA, null, null);
    final Completable completable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, requestData);
    assertThat(completable.blockingGet()).isNull();
    final TopicData expected = new TopicData(topicName, TopicWriteType.MUTABLE, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, SCHEMA);
    assertThat(this.topicRegistryClient.getTopicData(topicName).blockingGet()).usingRecursiveComparison().isEqualTo(expected);
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) Completable(io.reactivex.Completable) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) TopicData(com.bakdata.quick.common.api.model.TopicData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 9 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class KafkaTopicServiceTest method shouldRegisterTopicAvroSchema.

@Test
void shouldRegisterTopicAvroSchema() throws IOException, RestClientException {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    when(this.gatewayService.getGateway(GATEWAY_SCHEMA.getGateway())).thenReturn(Single.just(new GatewayDescription("test", 1, "latest")));
    when(this.gatewayClient.getWriteSchema(anyString(), anyString())).thenReturn(Single.just(new SchemaData(SCHEMA)));
    final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, GATEWAY_SCHEMA, null, null);
    final Completable completable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, requestData);
    assertThat(completable.blockingGet()).isNull();
    final SchemaRegistryClient schemaRegistryClient = this.schemaRegistry.getSchemaRegistryClient();
    final String subject = topicName + "-value";
    final Schema expectedSchema = this.graphQLToAvroConverter.convertToSchema(SCHEMA);
    assertThat(schemaRegistryClient.getAllSubjects()).containsExactly(subject);
    assertThat(schemaRegistryClient.getBySubjectAndId(subject, 1)).isEqualTo(expectedSchema);
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) Completable(io.reactivex.Completable) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) Schema(org.apache.avro.Schema) GatewaySchema(com.bakdata.quick.common.api.model.manager.GatewaySchema) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) Test(org.junit.jupiter.api.Test)

Example 10 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class GatewayControllerTest method shouldGetGatewayGraphQLSchema.

@Test
void shouldGetGatewayGraphQLSchema() {
    final String schema = "type Test { test: Int }";
    final SchemaData schemaData = new SchemaData(schema);
    final GatewayDescription gatewayDescription = new GatewayDescription(GATEWAY_NAME, 1, null);
    when(this.gatewayService.getGateway(GATEWAY_NAME)).thenReturn(Single.just(gatewayDescription));
    when(this.gatewayService.getGatewayWriteSchema(GATEWAY_NAME, "Test", SchemaFormat.GRAPHQL)).thenReturn(Single.just(schemaData));
    final String uri = UriBuilder.of(BASE_PATH + "/schema/{type}/graphql").expand(Map.of("name", GATEWAY_NAME, "type", "Test")).toString();
    assertEquals("/gateway/test-gateway/schema/Test/graphql", uri);
    final SchemaData graphqlSchema = this.client.toBlocking().retrieve(GET(uri), SchemaData.class);
    assertThat(graphqlSchema).isEqualTo(new SchemaData(schema));
}
Also used : SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaData (com.bakdata.quick.common.api.model.gateway.SchemaData)13 Test (org.junit.jupiter.api.Test)10 GatewayDescription (com.bakdata.quick.common.api.model.manager.GatewayDescription)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Completable (io.reactivex.Completable)6 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)5 TopicCreationData (com.bakdata.quick.common.api.model.manager.creation.TopicCreationData)4 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)3 GatewaySchema (com.bakdata.quick.common.api.model.manager.GatewaySchema)2 GatewayClient (com.bakdata.quick.common.api.client.GatewayClient)1 ErrorMessage (com.bakdata.quick.common.api.model.ErrorMessage)1 TopicData (com.bakdata.quick.common.api.model.TopicData)1 GatewayCreationData (com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData)1 MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)1 GatewayResourceLoader (com.bakdata.quick.manager.gateway.resource.GatewayResourceLoader)1 GraphQLToAvroConverter (com.bakdata.quick.manager.graphql.GraphQLToAvroConverter)1 KubernetesResources (com.bakdata.quick.manager.k8s.KubernetesResources)1 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)1 MiddlewareList (com.bakdata.quick.manager.k8s.middleware.MiddlewareList)1 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1