io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString Java Examples

The following examples show how to use io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchemaRegistryMock.java    From fluent-kafka-streams-tests with MIT License 6 votes vote down vote up
private int register(final String subject, final Schema schema) {
    try {
        final int id = this.schemaRegistryClient.register(subject, schema);
        this.mockSchemaRegistry.stubFor(WireMock.get(getSchemaPattern(id))
                .withQueryParam("fetchMaxId", WireMock.matching("false|true"))
                .willReturn(ResponseDefinitionBuilder.okForJson(new SchemaString(schema.toString()))));
        this.mockSchemaRegistry.stubFor(WireMock.delete(getSubjectPattern(subject))
                .willReturn(WireMock.aResponse().withTransformers(this.deleteSubjectHandler.getName())));
        this.mockSchemaRegistry.stubFor(WireMock.get(getSubjectVersionsPattern(subject))
                .willReturn(WireMock.aResponse().withTransformers(this.listVersionsHandler.getName())));
        this.mockSchemaRegistry.stubFor(WireMock.get(getSubjectVersionPattern(subject))
                .willReturn(WireMock.aResponse().withTransformers(this.getVersionHandler.getName())));
        log.debug("Registered schema {}", id);
        return id;
    } catch (final IOException | RestClientException e) {
        throw new IllegalStateException("Internal error in mock schema registry client", e);
    }
}
 
Example #2
Source File: HermesKafkaAvroSerializerTest.java    From hermes with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
	String schemaString = "{\"namespace\": \"com.ctrip.hermes.kafka.avro\", \"type\": \"record\", \"name\": \"AvroVisitEvent\", \"fields\": [ {\"name\": \"ip\", \"type\": \"string\"}, {\"name\": \"url\", \"type\": \"string\"}, {\"name\": \"tz\", \"type\": \"long\", \"java-class\":\"java.util.Date\"} ] }";

	SchemaRegisterRestClient restService = Mockito.mock(SchemaRegisterRestClient.class);
	Mockito.when(restService.registerSchema(Mockito.anyString(), Mockito.anyString())).thenReturn(MOCK_ID);
	Mockito.when(restService.getId(Mockito.anyInt())).thenReturn(new SchemaString(schemaString));

	m_serializer = new HermesKafkaAvroSerializer();
	m_deserializer = new HermesKafkaAvroDeserializer();

	m_serializer.setSchemaRestService(restService);
	Map<String, String> configs = new HashMap<String, String>();
	m_serializer.configure(configs, false);
	configs.put(KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG, Boolean.TRUE.toString());
	m_deserializer.setSchemaRestService(restService);
	m_deserializer.configure(configs, false);
}
 
Example #3
Source File: SchemaRegistryMock.java    From schema-registry-transfer-smt with Apache License 2.0 5 votes vote down vote up
private int register(final String subject, final Schema schema) {
    try {
        final int id = this.schemaRegistryClient.register(subject, schema);
        this.stubFor.apply(WireMock.get(WireMock.urlEqualTo(SCHEMA_BY_ID_PATTERN + id))
                .willReturn(ResponseDefinitionBuilder.okForJson(new SchemaString(schema.toString()))));
        log.debug("Registered schema {}", id);
        return id;
    } catch (final IOException | RestClientException e) {
        throw new IllegalStateException("Internal error in mock schema registry client", e);
    }
}
 
Example #4
Source File: KafkaSchemaServiceImpl.java    From griffin with Apache License 2.0 5 votes vote down vote up
@Override
public SchemaString getSchemaString(Integer id) {
    String path = "/schemas/ids/" + id;
    String regUrl = registryUrl(path);
    ResponseEntity<SchemaString> res = restTemplate.getForEntity(regUrl,
        SchemaString.class);
    SchemaString result = res.getBody();
    return result;
}
 
Example #5
Source File: KafkaSchemaControllerTest.java    From griffin with Apache License 2.0 5 votes vote down vote up
@Test
public void test_getSubjects() throws Exception {
    int id = 1;
    SchemaString ss = new SchemaString();
    when(kafkaSchemaService.getSchemaString(id)).thenReturn(ss);
    mockMvc.perform(get(API_PATH + "/schema/{id}", id))
            .andExpect(status().isOk());
    verify(kafkaSchemaService).getSchemaString(id);
}
 
Example #6
Source File: KafkaSchemaServiceImplTest.java    From griffin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSchemaString() {
    try {
        SchemaString ss = new SchemaString();
        ResponseEntity entity = mock(ResponseEntity.class);
        when(service.restTemplate.getForEntity(
                "${kafka.schema.registry.url}/schemas/ids/1",
                SchemaString.class)).thenReturn(entity);
        when(entity.getBody()).thenReturn(ss);
        service.getSchemaString(1);
        assertTrue(true);
    } catch (Throwable t) {
        fail("Cannot get all tables from all dbs");
    }
}
 
Example #7
Source File: SchemaRegisterRestClient.java    From hermes with Apache License 2.0 4 votes vote down vote up
@Override
public SchemaString getId(Map<String, String> requestProperties, int id) throws IOException, RestClientException {
	return new SchemaString(m_metaManager.getMetaProxy().getSchemaString(id));
}
 
Example #8
Source File: KafkaSchemaController.java    From griffin with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/schema/{id}", method = RequestMethod.GET)
public SchemaString getSchemaString(@PathVariable("id") Integer id) {
    return kafkaSchemaService.getSchemaString(id);
}
 
Example #9
Source File: BCachedSchemaRegistryClient.java    From replicator with Apache License 2.0 4 votes vote down vote up
private Schema getSchemaByIdFromRegistry(int id) throws IOException, RestClientException {
    SchemaString restSchema = this.restService.getId(id);
    return (new Schema.Parser()).parse(restSchema.getSchemaString());
}
 
Example #10
Source File: KafkaSchemaService.java    From griffin with Apache License 2.0 votes vote down vote up
SchemaString getSchemaString(Integer id);