Add more test when creating new schemas/versions
This commit is contained in:
parent
198630ae35
commit
ff1d823572
2 changed files with 59 additions and 6 deletions
|
@ -1,13 +1,16 @@
|
||||||
package com.provectus.kafka.ui.cluster.model.schemaregistry;
|
package com.provectus.kafka.ui.cluster.model.schemaregistry;
|
||||||
|
|
||||||
import com.provectus.kafka.ui.model.NewSchemaSubject;
|
import com.provectus.kafka.ui.model.NewSchemaSubject;
|
||||||
|
import com.provectus.kafka.ui.model.SchemaType;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class InternalNewSchema {
|
public class InternalNewSchema {
|
||||||
private String schema;
|
private String schema;
|
||||||
|
private SchemaType schemaType;
|
||||||
|
|
||||||
public InternalNewSchema(NewSchemaSubject schemaSubject) {
|
public InternalNewSchema(NewSchemaSubject schemaSubject) {
|
||||||
this.schema = schemaSubject.getSchema();
|
this.schema = schemaSubject.getSchema();
|
||||||
|
this.schemaType = schemaSubject.getSchemaType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.provectus.kafka.ui;
|
package com.provectus.kafka.ui;
|
||||||
|
|
||||||
import com.provectus.kafka.ui.model.CompatibilityLevel;
|
import com.provectus.kafka.ui.model.CompatibilityLevel;
|
||||||
|
import com.provectus.kafka.ui.model.NewSchemaSubject;
|
||||||
import com.provectus.kafka.ui.model.SchemaSubject;
|
import com.provectus.kafka.ui.model.SchemaSubject;
|
||||||
import com.provectus.kafka.ui.model.SchemaType;
|
import com.provectus.kafka.ui.model.SchemaType;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
@ -10,11 +11,13 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
|
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.web.reactive.server.EntityExchangeResult;
|
import org.springframework.test.web.reactive.server.EntityExchangeResult;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
import org.springframework.web.reactive.function.BodyInserters;
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -51,6 +54,53 @@ class SchemaRegistryServiceTests extends AbstractBaseTest {
|
||||||
.expectStatus().isNotFound();
|
.expectStatus().isNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturn409WhenSchemaDuplicatesThePreviousVersion() {
|
||||||
|
String schema = "{\"subject\":\"%s\",\"schemaType\":\"AVRO\",\"schema\":\"{\\\"type\\\": \\\"string\\\"}\"}";
|
||||||
|
|
||||||
|
webTestClient
|
||||||
|
.post()
|
||||||
|
.uri("/api/clusters/{clusterName}/schemas", LOCAL)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.body(BodyInserters.fromValue(schema.formatted(subject)))
|
||||||
|
.exchange()
|
||||||
|
.expectStatus().isEqualTo(HttpStatus.OK);
|
||||||
|
|
||||||
|
webTestClient
|
||||||
|
.post()
|
||||||
|
.uri("/api/clusters/{clusterName}/schemas", LOCAL)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.body(BodyInserters.fromValue(schema.formatted(subject)))
|
||||||
|
.exchange()
|
||||||
|
.expectStatus().isEqualTo(HttpStatus.CONFLICT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldCreateNewProtobufSchema() {
|
||||||
|
String schema = "syntax = \"proto3\";\n\nmessage MyRecord {\n int32 id = 1;\n string name = 2;\n}\n";
|
||||||
|
NewSchemaSubject requestBody = new NewSchemaSubject()
|
||||||
|
.schemaType(SchemaType.PROTOBUF)
|
||||||
|
.subject(subject)
|
||||||
|
.schema(schema);
|
||||||
|
SchemaSubject actual = webTestClient
|
||||||
|
.post()
|
||||||
|
.uri("/api/clusters/{clusterName}/schemas", LOCAL)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.body(BodyInserters.fromPublisher(Mono.just(requestBody), NewSchemaSubject.class))
|
||||||
|
.exchange()
|
||||||
|
.expectStatus()
|
||||||
|
.isOk()
|
||||||
|
.expectBody(SchemaSubject.class)
|
||||||
|
.returnResult()
|
||||||
|
.getResponseBody();
|
||||||
|
|
||||||
|
Assertions.assertNotNull(actual);
|
||||||
|
Assertions.assertEquals(CompatibilityLevel.CompatibilityEnum.BACKWARD.name(), actual.getCompatibilityLevel());
|
||||||
|
Assertions.assertEquals("1", actual.getVersion());
|
||||||
|
Assertions.assertEquals(SchemaType.PROTOBUF, actual.getSchemaType());
|
||||||
|
Assertions.assertEquals(schema, actual.getSchema());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnBackwardAsGlobalCompatibilityLevelByDefault() {
|
public void shouldReturnBackwardAsGlobalCompatibilityLevelByDefault() {
|
||||||
webTestClient
|
webTestClient
|
||||||
|
@ -135,7 +185,7 @@ class SchemaRegistryServiceTests extends AbstractBaseTest {
|
||||||
.post()
|
.post()
|
||||||
.uri("/api/clusters/{clusterName}/schemas", LOCAL)
|
.uri("/api/clusters/{clusterName}/schemas", LOCAL)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.body(BodyInserters.fromValue("{\"subject\":\"%s\",\"schemaType\":\"JSON\",\"schema\":\"{\\\"type\\\": \\\"string\\\"}\"}".formatted(subject)))
|
.body(BodyInserters.fromValue("{\"subject\":\"%s\",\"schemaType\":\"AVRO\",\"schema\":\"{\\\"type\\\": \\\"string\\\"}\"}".formatted(subject)))
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
.expectBody(SchemaSubject.class)
|
.expectBody(SchemaSubject.class)
|
||||||
|
@ -159,10 +209,10 @@ class SchemaRegistryServiceTests extends AbstractBaseTest {
|
||||||
private void assertResponseBodyWhenCreateNewSchema(EntityExchangeResult<SchemaSubject> exchangeResult) {
|
private void assertResponseBodyWhenCreateNewSchema(EntityExchangeResult<SchemaSubject> exchangeResult) {
|
||||||
SchemaSubject responseBody = exchangeResult.getResponseBody();
|
SchemaSubject responseBody = exchangeResult.getResponseBody();
|
||||||
Assertions.assertNotNull(responseBody);
|
Assertions.assertNotNull(responseBody);
|
||||||
Assertions.assertEquals(1, responseBody.getId(), "The schema ID should be non-null in the response");
|
Assertions.assertEquals("1", responseBody.getVersion());
|
||||||
String message = "It should be null";
|
Assertions.assertNotNull(responseBody.getSchema());
|
||||||
Assertions.assertNotNull(responseBody.getSchema(), message);
|
Assertions.assertNotNull(responseBody.getSubject());
|
||||||
Assertions.assertNotNull(responseBody.getSubject(), message);
|
Assertions.assertNotNull(responseBody.getCompatibilityLevel());
|
||||||
Assertions.assertNotNull(responseBody.getVersion(), message);
|
Assertions.assertEquals(SchemaType.AVRO, responseBody.getSchemaType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue