55import lombok .extern .log4j .Log4j2 ;
66import lombok .val ;
77import org .junit .jupiter .api .Assertions ;
8+ import org .junit .jupiter .api .BeforeEach ;
89import org .junit .jupiter .api .Test ;
910import org .springframework .beans .factory .annotation .Autowired ;
1011import org .springframework .boot .test .autoconfigure .web .reactive .AutoConfigureWebTestClient ;
2324class SchemaRegistryServiceTests extends AbstractBaseTest {
2425 @ Autowired
2526 WebTestClient webTestClient ;
27+ String subject ;
28+
29+ @ BeforeEach
30+ void setUpBefore () {
31+ this .subject = UUID .randomUUID ().toString ();
32+ }
2633
2734 @ Test
2835 public void should404WhenGetAllSchemasForUnknownCluster () {
@@ -34,11 +41,11 @@ public void should404WhenGetAllSchemasForUnknownCluster() {
3441 }
3542
3643 @ Test
37- void shouldReturn404WhenGetLatestSchemaByNonExistingSchemaName () {
44+ void shouldReturn404WhenGetLatestSchemaByNonExistingSubject () {
3845 String unknownSchema = "unknown-schema" ;
3946 webTestClient
4047 .get ()
41- .uri ("http://localhost:8080/api/clusters/local/schemas/{schemaName }/latest" , unknownSchema )
48+ .uri ("http://localhost:8080/api/clusters/local/schemas/{subject }/latest" , unknownSchema )
4249 .exchange ()
4350 .expectStatus ().isNotFound ();
4451 }
@@ -59,49 +66,51 @@ void shouldReturnBackwardAsGlobalCompatibilityLevelByDefault() {
5966 }
6067
6168 @ Test
62- public void shouldReturnNotNullResponseWhenGetAllSchemas () {
69+ public void shouldReturnNotEmptyResponseWhenGetAllSchemas () {
70+ createNewSubjectAndAssert (subject );
71+
6372 webTestClient
6473 .get ()
6574 .uri ("http://localhost:8080/api/clusters/local/schemas" )
6675 .exchange ()
6776 .expectStatus ().isOk ()
68- .expectBodyList (String .class )
77+ .expectBodyList (SchemaSubject .class )
6978 .consumeWith (result -> {
70- List <String > responseBody = result .getResponseBody ();
71- Assertions .assertNotNull (responseBody );
79+ List <SchemaSubject > responseBody = result .getResponseBody ();
7280 log .info ("Response of test schemas: {}" , responseBody );
81+ Assertions .assertNotNull (responseBody );
82+ Assertions .assertFalse (responseBody .isEmpty ());
83+
84+ SchemaSubject actualSchemaSubject = responseBody .stream ()
85+ .filter (schemaSubject -> subject .equals (schemaSubject .getSubject ()))
86+ .findFirst ()
87+ .orElseThrow ();
88+ Assertions .assertNotNull (actualSchemaSubject .getId ());
89+ Assertions .assertNotNull (actualSchemaSubject .getVersion ());
90+ Assertions .assertNotNull (actualSchemaSubject .getCompatibilityLevel ());
91+ Assertions .assertEquals ("\" string\" " , actualSchemaSubject .getSchema ());
7392 });
7493 }
7594
7695 @ Test
7796 public void shouldOkWhenCreateNewSchemaThenGetAndUpdateItsCompatibilityLevel () {
78- String schemaName = UUID .randomUUID ().toString ();
79- // Create a new schema
80- webTestClient
81- .post ()
82- .uri ("http://localhost:8080/api/clusters/local/schemas/{schemaName}" , schemaName )
83- .contentType (MediaType .APPLICATION_JSON )
84- .body (BodyInserters .fromValue ("{\" schema\" :\" {\\ \" type\\ \" : \\ \" string\\ \" }\" }" ))
85- .exchange ()
86- .expectStatus ().isOk ()
87- .expectBody (SchemaSubject .class )
88- .consumeWith (this ::assertResponseBodyWhenCreateNewSchema );
97+ createNewSubjectAndAssert (subject );
8998
9099 //Get the created schema and check its items
91100 webTestClient
92101 .get ()
93- .uri ("http://localhost:8080/api/clusters/local/schemas/{schemaName }/latest" , schemaName )
102+ .uri ("http://localhost:8080/api/clusters/local/schemas/{subject }/latest" , subject )
94103 .exchange ()
95104 .expectStatus ().isOk ()
96105 .expectBodyList (SchemaSubject .class )
97106 .consumeWith (listEntityExchangeResult -> {
98107 val expectedCompatibility = CompatibilityLevel .CompatibilityEnum .BACKWARD ;
99- assertSchemaWhenGetLatest (schemaName , listEntityExchangeResult , expectedCompatibility );
108+ assertSchemaWhenGetLatest (subject , listEntityExchangeResult , expectedCompatibility );
100109 });
101110
102111 //Now let's change compatibility level of this schema to FULL whereas the global level should be BACKWARD
103112 webTestClient .put ()
104- .uri ("http://localhost:8080/api/clusters/local/schemas/{schemaName }/compatibility" , schemaName )
113+ .uri ("http://localhost:8080/api/clusters/local/schemas/{subject }/compatibility" , subject )
105114 .contentType (MediaType .APPLICATION_JSON )
106115 .body (BodyInserters .fromValue ("{\" compatibility\" :\" FULL\" }" ))
107116 .exchange ()
@@ -110,23 +119,35 @@ public void shouldOkWhenCreateNewSchemaThenGetAndUpdateItsCompatibilityLevel() {
110119 //Get one more time to check the schema compatibility level is changed to FULL
111120 webTestClient
112121 .get ()
113- .uri ("http://localhost:8080/api/clusters/local/schemas/{schemaName }/latest" , schemaName )
122+ .uri ("http://localhost:8080/api/clusters/local/schemas/{subject }/latest" , subject )
114123 .exchange ()
115124 .expectStatus ().isOk ()
116125 .expectBodyList (SchemaSubject .class )
117126 .consumeWith (listEntityExchangeResult -> {
118127 val expectedCompatibility = CompatibilityLevel .CompatibilityEnum .FULL ;
119- assertSchemaWhenGetLatest (schemaName , listEntityExchangeResult , expectedCompatibility );
128+ assertSchemaWhenGetLatest (subject , listEntityExchangeResult , expectedCompatibility );
120129 });
121130 }
122131
123- private void assertSchemaWhenGetLatest (String schemaName , EntityExchangeResult <List <SchemaSubject >> listEntityExchangeResult , CompatibilityLevel .CompatibilityEnum expectedCompatibility ) {
132+ private void createNewSubjectAndAssert (String subject ) {
133+ webTestClient
134+ .post ()
135+ .uri ("http://localhost:8080/api/clusters/local/schemas/{subject}" , subject )
136+ .contentType (MediaType .APPLICATION_JSON )
137+ .body (BodyInserters .fromValue ("{\" schema\" :\" {\\ \" type\\ \" : \\ \" string\\ \" }\" }" ))
138+ .exchange ()
139+ .expectStatus ().isOk ()
140+ .expectBody (SchemaSubject .class )
141+ .consumeWith (this ::assertResponseBodyWhenCreateNewSchema );
142+ }
143+
144+ private void assertSchemaWhenGetLatest (String subject , EntityExchangeResult <List <SchemaSubject >> listEntityExchangeResult , CompatibilityLevel .CompatibilityEnum expectedCompatibility ) {
124145 List <SchemaSubject > responseBody = listEntityExchangeResult .getResponseBody ();
125146 Assertions .assertNotNull (responseBody );
126147 Assertions .assertEquals (1 , responseBody .size ());
127148 SchemaSubject actualSchema = responseBody .get (0 );
128149 Assertions .assertNotNull (actualSchema );
129- Assertions .assertEquals (schemaName , actualSchema .getSubject ());
150+ Assertions .assertEquals (subject , actualSchema .getSubject ());
130151 Assertions .assertEquals ("\" string\" " , actualSchema .getSchema ());
131152
132153 Assertions .assertNotNull (actualSchema .getCompatibilityLevel ());
0 commit comments