Rename getLatestSchema method and update tests
This commit is contained in:
parent
3d75853cbc
commit
3b92ba5664
3 changed files with 38 additions and 11 deletions
|
@ -105,7 +105,7 @@ public class MetricsRestController implements ApiClustersApi {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mono<ResponseEntity<Flux<SchemaSubject>>> getLatestSchemaByVersion(String clusterName, String schemaName, ServerWebExchange exchange) {
|
||||
public Mono<ResponseEntity<Flux<SchemaSubject>>> getLatestSchema(String clusterName, String schemaName, ServerWebExchange exchange) {
|
||||
Flux<SchemaSubject> flux = schemaRegistryService.getLatestSchemaSubject(clusterName, schemaName);
|
||||
return Mono.just(ResponseEntity.ok(flux)).onErrorReturn(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.provectus.kafka.ui;
|
|||
|
||||
import com.provectus.kafka.ui.model.SchemaSubject;
|
||||
import com.provectus.kafka.ui.rest.MetricsRestController;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -11,37 +12,63 @@ import org.springframework.test.web.reactive.server.EntityExchangeResult;
|
|||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ContextConfiguration(initializers = {AbstractBaseTest.Initializer.class})
|
||||
@Log4j2
|
||||
class SchemaRegistryServiceTests extends AbstractBaseTest {
|
||||
@Autowired
|
||||
MetricsRestController metricsRestController;
|
||||
|
||||
@Test
|
||||
public void shouldReturnEmptyRespWhenGetAllSchemas() {
|
||||
public void shouldReturnNotNullResponseWhenGetAllSchemas() {
|
||||
WebTestClient.bindToController(metricsRestController)
|
||||
.build()
|
||||
.get()
|
||||
.uri("http://localhost:8080/api/clusters/local/schemas")
|
||||
.exchange()
|
||||
.expectStatus().is2xxSuccessful();
|
||||
.expectStatus().isOk()
|
||||
.expectBodyList(String.class)
|
||||
.consumeWith(result -> {
|
||||
List<String> responseBody = result.getResponseBody();
|
||||
Assertions.assertNotNull(responseBody);
|
||||
log.info("Response of test schemas: {}", responseBody);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSuccessWhenCreateNewSchema() {
|
||||
String schemaName = UUID.randomUUID().toString();
|
||||
String url = "http://localhost:8080/api/clusters/local/schemas/{schemaName}";
|
||||
public void shouldReturnSuccessAndSchemaIdWhenCreateNewSchema() {
|
||||
WebTestClient webTestClient = WebTestClient.bindToController(metricsRestController).build();
|
||||
|
||||
WebTestClient.bindToController(metricsRestController)
|
||||
.build()
|
||||
String schemaName = UUID.randomUUID().toString();
|
||||
webTestClient
|
||||
.post()
|
||||
.uri(url, schemaName)
|
||||
.uri("http://localhost:8080/api/clusters/local/schemas/{schemaName}", schemaName)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(BodyInserters.fromValue("{\"schema\":\"{\\\"type\\\": \\\"string\\\"}\"}"))
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody(SchemaSubject.class).consumeWith(this::assertResponseBodyWhenCreateNewSchema);
|
||||
.expectBody(SchemaSubject.class)
|
||||
.consumeWith(this::assertResponseBodyWhenCreateNewSchema);
|
||||
|
||||
webTestClient
|
||||
.get()
|
||||
.uri("http://localhost:8080/api/clusters/local/schemas/{schemaName}/latest", schemaName)
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBodyList(SchemaSubject.class)
|
||||
.consumeWith(listEntityExchangeResult -> assertSchemaWhenGetLatest(schemaName, listEntityExchangeResult));
|
||||
}
|
||||
|
||||
private void assertSchemaWhenGetLatest(String schemaName, EntityExchangeResult<List<SchemaSubject>> listEntityExchangeResult) {
|
||||
List<SchemaSubject> responseBody = listEntityExchangeResult.getResponseBody();
|
||||
Assertions.assertNotNull(responseBody);
|
||||
Assertions.assertEquals(1, responseBody.size());
|
||||
SchemaSubject actualSchema = responseBody.get(0);
|
||||
Assertions.assertNotNull(actualSchema);
|
||||
Assertions.assertEquals(schemaName, actualSchema.getSubject());
|
||||
Assertions.assertEquals("\"string\"", actualSchema.getSchema());
|
||||
}
|
||||
|
||||
private void assertResponseBodyWhenCreateNewSchema(EntityExchangeResult<SchemaSubject> exchangeResult) {
|
||||
|
|
|
@ -442,7 +442,7 @@ paths:
|
|||
tags:
|
||||
- /api/clusters
|
||||
summary: get the latest schema from Schema Registry service
|
||||
operationId: getLatestSchemaByVersion
|
||||
operationId: getLatestSchema
|
||||
parameters:
|
||||
- name: clusterName
|
||||
in: path
|
||||
|
|
Loading…
Add table
Reference in a new issue