2020import static org .hamcrest .Matchers .notNullValue ;
2121import static org .junit .Assert .assertThrows ;
2222import static org .mockito .ArgumentMatchers .any ;
23+ import static org .mockito .ArgumentMatchers .anyBoolean ;
2324import static org .mockito .ArgumentMatchers .anyInt ;
2425import static org .mockito .ArgumentMatchers .anyString ;
2526import static org .mockito .Mockito .mock ;
3132import io .confluent .kafka .schemaregistry .avro .AvroSchema ;
3233import io .confluent .kafka .schemaregistry .client .SchemaMetadata ;
3334import io .confluent .kafka .schemaregistry .client .SchemaRegistryClient ;
35+ import io .confluent .kafka .schemaregistry .client .rest .entities .Metadata ;
36+ import io .confluent .kafka .schemaregistry .client .rest .entities .RuleSet ;
3437import io .confluent .kafka .schemaregistry .client .rest .entities .requests .RegisterSchemaResponse ;
3538import io .confluent .kafka .schemaregistry .client .rest .exceptions .RestClientException ;
3639import io .confluent .ksql .test .util .TestMethods ;
3740import io .confluent .ksql .test .util .TestMethods .TestCase ;
3841import java .util .Collection ;
42+ import java .util .Collections ;
43+ import java .util .List ;
3944import java .util .Objects ;
4045
46+ import java .util .Optional ;
4147import org .apache .avro .Schema ;
4248import org .apache .hc .core5 .http .HttpStatus ;
4349import org .junit .Before ;
@@ -78,8 +84,12 @@ public static Collection<TestCase<SchemaRegistryClient>> getMethodsToTest() {
7884 .ignore ("getId" , String .class , ParsedSchema .class )
7985 .ignore ("getId" , String .class , ParsedSchema .class , boolean .class )
8086 .ignore ("getId" , String .class , Schema .class )
87+ .ignore ("getIdWithResponse" , String .class , ParsedSchema .class , boolean .class )
8188 .ignore ("getVersion" , String .class , ParsedSchema .class )
8289 .ignore ("getSchemaById" , int .class )
90+ .ignore ("parseSchema" , io .confluent .kafka .schemaregistry .client .rest .entities .Schema .class )
91+ .ignore ("parseSchema" , String .class , String .class , List .class )
92+ .ignore ("parseSchema" , String .class , String .class , List .class , Metadata .class , RuleSet .class )
8393 .build ();
8494 }
8595
@@ -251,7 +261,52 @@ public void shouldGetIdFromCache() throws Exception {
251261
252262 // Then:
253263 assertThat (id , is (newId ));
264+ }
265+
266+ @ Test
267+ public void shouldGetIdWithResponse () throws Exception {
268+ // Given:
269+ when (delegate .getIdWithResponse (anyString (), any (ParsedSchema .class ), anyBoolean ()))
270+ .thenReturn (new RegisterSchemaResponse (123 ))
271+ .thenReturn (new RegisterSchemaResponse (124 ))
272+ .thenReturn (new RegisterSchemaResponse (125 ));
254273
274+ // When:
275+ final int id = sandboxedClient .getIdWithResponse ("some subject" , schema , false ).getId ();
276+ final int id1 = sandboxedClient .getIdWithResponse ("some subject" , parsedSchema , false ).getId ();
277+ final int id2 = sandboxedClient .getIdWithResponse ("some subject" , parsedSchema , true ).getId ();
278+
279+ // Then:
280+ assertThat (id , is (123 ));
281+ assertThat (id1 , is (124 ));
282+ assertThat (id2 , is (125 ));
283+ }
284+
285+ @ Test
286+ public void shouldGetIdWithResponseFromCache () throws Exception {
287+ // Given:
288+ final RestClientException exception = mock (RestClientException .class );
289+ when (exception .getStatus ()).thenReturn (HttpStatus .SC_NOT_FOUND );
290+ when (delegate .getIdWithResponse (anyString (), any (ParsedSchema .class ), anyBoolean ()))
291+ .thenThrow (exception );
292+
293+ final int newId = sandboxedClient .register ("newSubject" , parsedSchema );
294+
295+ // When:
296+ final int id = sandboxedClient .getIdWithResponse ("newSubject" , parsedSchema , false ).getId ();
297+
298+ // Then:
299+ assertThat (id , is (newId ));
300+ }
301+
302+ @ Test
303+ public void shouldParseSchema () throws Exception {
304+ // Given:
305+ final Optional <ParsedSchema > schema =
306+ sandboxedClient .parseSchema ("AVRO" , "\" string\" " , Collections .emptyList ());
307+
308+ // Then:
309+ assertThat (schema .get (), is (new AvroSchema ("\" string\" " )));
255310 }
256311 }
257312}
0 commit comments