SchemaRegistryServiceTests.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.provectus.kafka.ui;
  2. import com.provectus.kafka.ui.model.SchemaSubject;
  3. import com.provectus.kafka.ui.rest.MetricsRestController;
  4. import org.junit.jupiter.api.Assertions;
  5. import org.junit.jupiter.api.Test;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.http.MediaType;
  8. import org.springframework.test.context.ContextConfiguration;
  9. import org.springframework.test.web.reactive.server.EntityExchangeResult;
  10. import org.springframework.test.web.reactive.server.WebTestClient;
  11. import org.springframework.web.reactive.function.BodyInserters;
  12. import java.util.UUID;
  13. @ContextConfiguration(initializers = {AbstractBaseTest.Initializer.class})
  14. class SchemaRegistryServiceTests extends AbstractBaseTest {
  15. @Autowired
  16. MetricsRestController metricsRestController;
  17. @Test
  18. public void shouldReturnEmptyRespWhenGetAllSchemas() {
  19. WebTestClient.bindToController(metricsRestController)
  20. .build()
  21. .get()
  22. .uri("http://localhost:8080/api/clusters/local/schemas")
  23. .exchange()
  24. .expectStatus().is2xxSuccessful();
  25. }
  26. @Test
  27. public void shouldReturnSuccessWhenCreateNewSchema() {
  28. String schemaName = UUID.randomUUID().toString();
  29. String url = "http://localhost:8080/api/clusters/local/schemas/{schemaName}";
  30. WebTestClient.bindToController(metricsRestController)
  31. .build()
  32. .post()
  33. .uri(url, schemaName)
  34. .contentType(MediaType.APPLICATION_JSON)
  35. .body(BodyInserters.fromValue("{\"schema\":\"{\\\"type\\\": \\\"string\\\"}\"}"))
  36. .exchange()
  37. .expectStatus().isOk()
  38. .expectBody(SchemaSubject.class).consumeWith(this::assertResponseBodyWhenCreateNewSchema);
  39. }
  40. private void assertResponseBodyWhenCreateNewSchema(EntityExchangeResult<SchemaSubject> exchangeResult) {
  41. SchemaSubject responseBody = exchangeResult.getResponseBody();
  42. Assertions.assertNotNull(responseBody);
  43. Assertions.assertEquals(1, responseBody.getId(), "The schema ID should be non-null in the response");
  44. String message = "It should be null";
  45. Assertions.assertNull(responseBody.getSchema(), message);
  46. Assertions.assertNull(responseBody.getSubject(), message);
  47. Assertions.assertNull(responseBody.getVersion(), message);
  48. }
  49. }