Added checkstyle
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,4 +35,5 @@ import org.springframework.context.annotation.Import;
|
||||
@Documented
|
||||
@Import(SchemaServerConfiguration.class)
|
||||
public @interface EnableSchemaRegistryServer {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,10 +22,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
/**
|
||||
* @author Vinicius Carvalho
|
||||
*/
|
||||
// @checkstyle:off
|
||||
@SpringBootApplication
|
||||
@EnableSchemaRegistryServer
|
||||
public class SchemaRegistryServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SchemaRegistryServerApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,10 +51,12 @@ public class SchemaServerConfiguration {
|
||||
return new BeanFactoryPostProcessor() {
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
public void postProcessBeanFactory(
|
||||
ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
if (beanFactory instanceof BeanDefinitionRegistry) {
|
||||
EntityScanPackages.register((BeanDefinitionRegistry) beanFactory,
|
||||
Collections.singletonList(Schema.class.getPackage().getName()));
|
||||
Collections
|
||||
.singletonList(Schema.class.getPackage().getName()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,10 +46,11 @@ public class SchemaServerProperties {
|
||||
}
|
||||
|
||||
public boolean isAllowSchemaDeletion() {
|
||||
return allowSchemaDeletion;
|
||||
return this.allowSchemaDeletion;
|
||||
}
|
||||
|
||||
public void setAllowSchemaDeletion(boolean allowSchemaDeletion) {
|
||||
this.allowSchemaDeletion = allowSchemaDeletion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ public class ServerController {
|
||||
SchemaValidator validator = this.validators.get(schema.getFormat());
|
||||
|
||||
if (validator == null) {
|
||||
throw new UnsupportedFormatException(String.format(
|
||||
"Invalid format, supported types are: %s",
|
||||
StringUtils.collectionToCommaDelimitedString(this.validators.keySet())));
|
||||
throw new UnsupportedFormatException(
|
||||
String.format("Invalid format, supported types are: %s", StringUtils
|
||||
.collectionToCommaDelimitedString(this.validators.keySet())));
|
||||
}
|
||||
|
||||
if (!validator.isValid(schema.getDefinition())) {
|
||||
@@ -82,8 +82,9 @@ public class ServerController {
|
||||
}
|
||||
|
||||
Schema result;
|
||||
List<Schema> registeredEntities = this.repository.findBySubjectAndFormatOrderByVersion(
|
||||
schema.getSubject(), schema.getFormat());
|
||||
List<Schema> registeredEntities = this.repository
|
||||
.findBySubjectAndFormatOrderByVersion(schema.getSubject(),
|
||||
schema.getFormat());
|
||||
if (registeredEntities == null || registeredEntities.size() == 0) {
|
||||
schema.setVersion(1);
|
||||
result = this.repository.save(schema);
|
||||
@@ -116,8 +117,8 @@ public class ServerController {
|
||||
public ResponseEntity<Schema> findOne(@PathVariable("subject") String subject,
|
||||
@PathVariable("format") String format,
|
||||
@PathVariable("version") Integer version) {
|
||||
Schema schema = this.repository.findOneBySubjectAndFormatAndVersion(subject, format,
|
||||
version);
|
||||
Schema schema = this.repository.findOneBySubjectAndFormatAndVersion(subject,
|
||||
format, version);
|
||||
if (schema == null) {
|
||||
throw new SchemaNotFoundException("Could not find Schema");
|
||||
}
|
||||
@@ -134,12 +135,14 @@ public class ServerController {
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, produces = "application/json", path = "/{subject}/{format}")
|
||||
public ResponseEntity<List<Schema>> findBySubjectAndVersion(@PathVariable("subject") String subject,
|
||||
public ResponseEntity<List<Schema>> findBySubjectAndVersion(
|
||||
@PathVariable("subject") String subject,
|
||||
@PathVariable("format") String format) {
|
||||
List<Schema> schemas = repository.findBySubjectAndFormatOrderByVersion(subject, format);
|
||||
List<Schema> schemas = this.repository
|
||||
.findBySubjectAndFormatOrderByVersion(subject, format);
|
||||
if (schemas == null || schemas.size() == 0) {
|
||||
throw new SchemaNotFoundException(
|
||||
String.format("No schemas found for subject %s and format %s", subject, format));
|
||||
throw new SchemaNotFoundException(String.format(
|
||||
"No schemas found for subject %s and format %s", subject, format));
|
||||
}
|
||||
return new ResponseEntity<List<Schema>>(schemas, HttpStatus.OK);
|
||||
}
|
||||
@@ -149,8 +152,8 @@ public class ServerController {
|
||||
@PathVariable("format") String format,
|
||||
@PathVariable("version") Integer version) {
|
||||
if (this.schemaServerProperties.isAllowSchemaDeletion()) {
|
||||
Schema schema = this.repository.findOneBySubjectAndFormatAndVersion(subject, format,
|
||||
version);
|
||||
Schema schema = this.repository.findOneBySubjectAndFormatAndVersion(subject,
|
||||
format, version);
|
||||
deleteSchema(schema);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,8 +20,25 @@ package org.springframework.cloud.stream.schema.server.model;
|
||||
* @author Vinicius Carvalho
|
||||
*/
|
||||
public enum Compatibility {
|
||||
|
||||
/**
|
||||
* Backward compatibiltity.
|
||||
*/
|
||||
BACKWARD,
|
||||
|
||||
/**
|
||||
* Forward compatibility.
|
||||
*/
|
||||
FORWARD,
|
||||
|
||||
/**
|
||||
* Full compatibility.
|
||||
*/
|
||||
FULL,
|
||||
|
||||
/**
|
||||
* Lack of compatibility.
|
||||
*/
|
||||
INCOMPATIBLE;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,7 +51,7 @@ public class Schema {
|
||||
private String definition;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
@@ -59,7 +59,7 @@ public class Schema {
|
||||
}
|
||||
|
||||
public Integer getVersion() {
|
||||
return version;
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public void setVersion(Integer version) {
|
||||
@@ -67,7 +67,7 @@ public class Schema {
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
return this.subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
@@ -75,7 +75,7 @@ public class Schema {
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return format;
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
@@ -83,10 +83,11 @@ public class Schema {
|
||||
}
|
||||
|
||||
public String getDefinition() {
|
||||
return definition;
|
||||
return this.definition;
|
||||
}
|
||||
|
||||
public void setDefinition(String definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,10 +28,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public interface SchemaRepository extends PagingAndSortingRepository<Schema, Integer> {
|
||||
|
||||
@Transactional
|
||||
List<Schema> findBySubjectAndFormatOrderByVersion(String subject,
|
||||
String format);
|
||||
List<Schema> findBySubjectAndFormatOrderByVersion(String subject, String format);
|
||||
|
||||
@Transactional
|
||||
Schema findOneBySubjectAndFormatAndVersion(String subject, String format,
|
||||
Integer version);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -65,4 +65,5 @@ public class AvroSchemaValidator implements SchemaValidator {
|
||||
public String getFormat() {
|
||||
return "avro";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,9 @@ package org.springframework.cloud.stream.schema.server.support;
|
||||
* @author Vinicius Carvalho
|
||||
*/
|
||||
public class InvalidSchemaException extends RuntimeException {
|
||||
|
||||
public InvalidSchemaException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ package org.springframework.cloud.stream.schema.server.support;
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
public class SchemaDeletionNotAllowedException extends RuntimeException {
|
||||
|
||||
public SchemaDeletionNotAllowedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
@@ -27,4 +28,5 @@ public class SchemaDeletionNotAllowedException extends RuntimeException {
|
||||
public SchemaDeletionNotAllowedException() {
|
||||
super("Schema Deletion Not Allowed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,9 @@ package org.springframework.cloud.stream.schema.server.support;
|
||||
* @author Vinicius Carvalho
|
||||
*/
|
||||
public class SchemaNotFoundException extends RuntimeException {
|
||||
|
||||
public SchemaNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.cloud.stream.schema.server.model.Schema;
|
||||
public interface SchemaValidator {
|
||||
|
||||
/**
|
||||
* Verifies if a definition is a valid schema
|
||||
* Verifies if a definition is a valid schema.
|
||||
* @param definition - The textual representation of the schema file
|
||||
* @return true if valid, false otherwise
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ public interface SchemaValidator {
|
||||
|
||||
/**
|
||||
* Checks for compatibility between two schemas @see Compatibility class for types
|
||||
* This method may not be supported for certain formats
|
||||
* This method may not be supported for certain formats.
|
||||
* @param source - The textual representation of the schema to tested
|
||||
* @param other - The textual representation of the other schema to tested
|
||||
* @return {@link Compatibility}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,4 +24,5 @@ public class UnsupportedFormatException extends RuntimeException {
|
||||
public UnsupportedFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
@@ -2,4 +2,5 @@ spring:
|
||||
application:
|
||||
name: SchemaRegistryServer
|
||||
server:
|
||||
port: 8990
|
||||
port: 8990
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.stream.schema.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -44,8 +43,9 @@ import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
|
||||
properties = "spring.main.allow-bean-definition-overriding=true")
|
||||
// @checkstyle:off
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, properties = "spring.main.allow-bean-definition-overriding=true")
|
||||
// @checkstyle:on
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
public class SchemaRegistryServerAvroTests {
|
||||
|
||||
@@ -76,9 +76,9 @@ public class SchemaRegistryServerAvroTests {
|
||||
Schema schema = new Schema();
|
||||
schema.setFormat("spring");
|
||||
schema.setSubject("boot");
|
||||
ResponseEntity<Schema> response = client.postForEntity("http://localhost:8990/",
|
||||
schema, Schema.class);
|
||||
Assert.assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
ResponseEntity<Schema> response = this.client
|
||||
.postForEntity("http://localhost:8990/", schema, Schema.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,9 +87,9 @@ public class SchemaRegistryServerAvroTests {
|
||||
schema.setFormat("avro");
|
||||
schema.setSubject("boot");
|
||||
schema.setDefinition("{}");
|
||||
ResponseEntity<Schema> response = client.postForEntity("http://localhost:8990/",
|
||||
schema, Schema.class);
|
||||
Assert.assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
ResponseEntity<Schema> response = this.client
|
||||
.postForEntity("http://localhost:8990/", schema, Schema.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,17 +97,17 @@ public class SchemaRegistryServerAvroTests {
|
||||
Schema schema = new Schema();
|
||||
schema.setFormat("avro");
|
||||
schema.setSubject("org.springframework.cloud.stream.schema.User");
|
||||
schema.setDefinition(USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response = client.postForEntity("http://localhost:8990/",
|
||||
schema, Schema.class);
|
||||
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
||||
Assert.assertEquals(new Integer(1), response.getBody().getVersion());
|
||||
schema.setDefinition(this.USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response = this.client
|
||||
.postForEntity("http://localhost:8990/", schema, Schema.class);
|
||||
assertThat(response.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
assertThat(response.getBody().getVersion()).isEqualTo(new Integer(1));
|
||||
List<String> location = response.getHeaders().get(HttpHeaders.LOCATION);
|
||||
Assert.assertNotNull(location);
|
||||
ResponseEntity<Schema> persistedSchema = client.getForEntity(location.get(0),
|
||||
assertThat(location).isNotNull();
|
||||
ResponseEntity<Schema> persistedSchema = this.client.getForEntity(location.get(0),
|
||||
Schema.class);
|
||||
Assert.assertEquals(response.getBody().getId(),
|
||||
persistedSchema.getBody().getId());
|
||||
assertThat(persistedSchema.getBody().getId())
|
||||
.isEqualTo(response.getBody().getId());
|
||||
|
||||
}
|
||||
|
||||
@@ -116,26 +116,26 @@ public class SchemaRegistryServerAvroTests {
|
||||
Schema schema = new Schema();
|
||||
schema.setFormat("avro");
|
||||
schema.setSubject("org.springframework.cloud.stream.schema.User");
|
||||
schema.setDefinition(USER_SCHEMA_V1);
|
||||
schema.setDefinition(this.USER_SCHEMA_V1);
|
||||
|
||||
Schema schema2 = new Schema();
|
||||
schema2.setFormat("avro");
|
||||
schema2.setSubject("org.springframework.cloud.stream.schema.User");
|
||||
schema2.setDefinition(USER_SCHEMA_V2);
|
||||
schema2.setDefinition(this.USER_SCHEMA_V2);
|
||||
|
||||
ResponseEntity<Schema> response = client.postForEntity("http://localhost:8990/",
|
||||
schema, Schema.class);
|
||||
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
||||
Assert.assertEquals(new Integer(1), response.getBody().getVersion());
|
||||
ResponseEntity<Schema> response = this.client
|
||||
.postForEntity("http://localhost:8990/", schema, Schema.class);
|
||||
assertThat(response.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
assertThat(response.getBody().getVersion()).isEqualTo(new Integer(1));
|
||||
List<String> location = response.getHeaders().get(HttpHeaders.LOCATION);
|
||||
Assert.assertNotNull(location);
|
||||
assertThat(location).isNotNull();
|
||||
|
||||
ResponseEntity<Schema> response2 = client.postForEntity("http://localhost:8990/",
|
||||
schema2, Schema.class);
|
||||
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
||||
Assert.assertEquals(new Integer(2), response2.getBody().getVersion());
|
||||
ResponseEntity<Schema> response2 = this.client
|
||||
.postForEntity("http://localhost:8990/", schema2, Schema.class);
|
||||
assertThat(response.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
assertThat(response2.getBody().getVersion()).isEqualTo(new Integer(2));
|
||||
List<String> location2 = response2.getHeaders().get(HttpHeaders.LOCATION);
|
||||
Assert.assertNotNull(location2);
|
||||
assertThat(location2).isNotNull();
|
||||
|
||||
}
|
||||
|
||||
@@ -144,24 +144,24 @@ public class SchemaRegistryServerAvroTests {
|
||||
Schema schema = new Schema();
|
||||
schema.setFormat("avro");
|
||||
schema.setSubject("org.springframework.cloud.stream.schema.User");
|
||||
schema.setDefinition(USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response = client.postForEntity("http://localhost:8990/",
|
||||
schema, Schema.class);
|
||||
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
||||
Assert.assertEquals(new Integer(1), response.getBody().getVersion());
|
||||
schema.setDefinition(this.USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response = this.client
|
||||
.postForEntity("http://localhost:8990/", schema, Schema.class);
|
||||
assertThat(response.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
assertThat(response.getBody().getVersion()).isEqualTo(new Integer(1));
|
||||
List<String> location = response.getHeaders().get(HttpHeaders.LOCATION);
|
||||
Assert.assertNotNull(location);
|
||||
ResponseEntity<Schema> response2 = client.postForEntity("http://localhost:8990/",
|
||||
schema, Schema.class);
|
||||
Assert.assertEquals(response.getBody().getId(), response2.getBody().getId());
|
||||
assertThat(location).isNotNull();
|
||||
ResponseEntity<Schema> response2 = this.client
|
||||
.postForEntity("http://localhost:8990/", schema, Schema.class);
|
||||
assertThat(response2.getBody().getId()).isEqualTo(response.getBody().getId());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaNotfound() throws Exception {
|
||||
ResponseEntity<Schema> response = client
|
||||
ResponseEntity<Schema> response = this.client
|
||||
.getForEntity("http://localhost:8990/foo/avro/v42", Schema.class);
|
||||
Assert.assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,15 +169,15 @@ public class SchemaRegistryServerAvroTests {
|
||||
Schema schema = new Schema();
|
||||
schema.setFormat("avro");
|
||||
schema.setSubject("test");
|
||||
schema.setDefinition(USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = client.postForEntity("http://localhost:8990/",
|
||||
schema, Schema.class);
|
||||
Assert.assertTrue(response1.getStatusCode().is2xxSuccessful());
|
||||
schemaServerProperties.setAllowSchemaDeletion(true);
|
||||
client.delete("http://localhost:8990/test/avro/v1");
|
||||
ResponseEntity<Schema> response2 = client
|
||||
schema.setDefinition(this.USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = this.client
|
||||
.postForEntity("http://localhost:8990/", schema, Schema.class);
|
||||
assertThat(response1.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
this.schemaServerProperties.setAllowSchemaDeletion(true);
|
||||
this.client.delete("http://localhost:8990/test/avro/v1");
|
||||
ResponseEntity<Schema> response2 = this.client
|
||||
.getForEntity("http://localhost:8990/test/avro/v1", Schema.class);
|
||||
Assert.assertEquals(HttpStatus.NOT_FOUND, response2.getStatusCode());
|
||||
assertThat(response2.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,18 +185,18 @@ public class SchemaRegistryServerAvroTests {
|
||||
Schema schema = new Schema();
|
||||
schema.setFormat("avro");
|
||||
schema.setSubject("test");
|
||||
schema.setDefinition(USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = client.postForEntity("http://localhost:8990/",
|
||||
schema, Schema.class);
|
||||
Assert.assertTrue(response1.getStatusCode().is2xxSuccessful());
|
||||
ResponseEntity<Schema> response2 = client
|
||||
schema.setDefinition(this.USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = this.client
|
||||
.postForEntity("http://localhost:8990/", schema, Schema.class);
|
||||
assertThat(response1.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
ResponseEntity<Schema> response2 = this.client
|
||||
.getForEntity("http://localhost:8990/test/avro/v1", Schema.class);
|
||||
Assert.assertEquals(HttpStatus.OK, response2.getStatusCode());
|
||||
schemaServerProperties.setAllowSchemaDeletion(true);
|
||||
client.delete("http://localhost:8990/schemas/1");
|
||||
ResponseEntity<Schema> response3 = client
|
||||
assertThat(response2.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
this.schemaServerProperties.setAllowSchemaDeletion(true);
|
||||
this.client.delete("http://localhost:8990/schemas/1");
|
||||
ResponseEntity<Schema> response3 = this.client
|
||||
.getForEntity("http://localhost:8990/test/avro/1", Schema.class);
|
||||
Assert.assertEquals(HttpStatus.NOT_FOUND, response3.getStatusCode());
|
||||
assertThat(response3.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -204,30 +204,32 @@ public class SchemaRegistryServerAvroTests {
|
||||
Schema schema1 = new Schema();
|
||||
schema1.setFormat("avro");
|
||||
schema1.setSubject("test");
|
||||
schema1.setDefinition(USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = client.postForEntity("http://localhost:8990/",
|
||||
schema1, Schema.class);
|
||||
Assert.assertTrue(response1.getStatusCode().is2xxSuccessful());
|
||||
Assert.assertEquals(HttpStatus.OK,
|
||||
client.getForEntity("http://localhost:8990/test/avro/v1", Schema.class).getStatusCode());
|
||||
client.getForEntity("http://localhost:8990/test/avro/1", Schema.class);
|
||||
schema1.setDefinition(this.USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = this.client
|
||||
.postForEntity("http://localhost:8990/", schema1, Schema.class);
|
||||
assertThat(response1.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
assertThat(this.client
|
||||
.getForEntity("http://localhost:8990/test/avro/v1", Schema.class)
|
||||
.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
this.client.getForEntity("http://localhost:8990/test/avro/1", Schema.class);
|
||||
Schema schema2 = new Schema();
|
||||
schema2.setFormat("avro");
|
||||
schema2.setSubject("test");
|
||||
schema2.setDefinition(USER_SCHEMA_V2);
|
||||
ResponseEntity<Schema> response2 = client.postForEntity("http://localhost:8990/",
|
||||
schema2, Schema.class);
|
||||
Assert.assertTrue(response2.getStatusCode().is2xxSuccessful());
|
||||
Assert.assertEquals(HttpStatus.OK,
|
||||
client.getForEntity("http://localhost:8990/test/avro/v2", Schema.class).getStatusCode());
|
||||
schemaServerProperties.setAllowSchemaDeletion(true);
|
||||
client.delete("http://localhost:8990/test");
|
||||
ResponseEntity<Schema> response4 = client
|
||||
schema2.setDefinition(this.USER_SCHEMA_V2);
|
||||
ResponseEntity<Schema> response2 = this.client
|
||||
.postForEntity("http://localhost:8990/", schema2, Schema.class);
|
||||
assertThat(response2.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
assertThat(this.client
|
||||
.getForEntity("http://localhost:8990/test/avro/v2", Schema.class)
|
||||
.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
this.schemaServerProperties.setAllowSchemaDeletion(true);
|
||||
this.client.delete("http://localhost:8990/test");
|
||||
ResponseEntity<Schema> response4 = this.client
|
||||
.getForEntity("http://localhost:8990/test/avro/v1", Schema.class);
|
||||
Assert.assertEquals(HttpStatus.NOT_FOUND, response4.getStatusCode());
|
||||
ResponseEntity<Schema> response5 = client
|
||||
assertThat(response4.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
ResponseEntity<Schema> response5 = this.client
|
||||
.getForEntity("http://localhost:8990/test/avro/v2", Schema.class);
|
||||
Assert.assertEquals(HttpStatus.NOT_FOUND, response5.getStatusCode());
|
||||
assertThat(response5.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,19 +237,21 @@ public class SchemaRegistryServerAvroTests {
|
||||
Schema schema = new Schema();
|
||||
schema.setFormat("avro");
|
||||
schema.setSubject("test");
|
||||
schema.setDefinition(USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = client.postForEntity("http://localhost:8990/",
|
||||
schema, Schema.class);
|
||||
Assert.assertTrue(response1.getStatusCode().is2xxSuccessful());
|
||||
ResponseEntity<Object> deleteBySubjectFormatVersion = client.exchange("http://localhost:8990/test/avro/v1",
|
||||
HttpMethod.DELETE,
|
||||
null, Object.class);
|
||||
assertThat(deleteBySubjectFormatVersion.getStatusCode()).isEqualTo(HttpStatus.METHOD_NOT_ALLOWED);
|
||||
ResponseEntity<Object> deleteBySubject = client.exchange("http://localhost:8990/test", HttpMethod.DELETE,
|
||||
null, Object.class);
|
||||
assertThat(deleteBySubject.getStatusCode()).isEqualTo(HttpStatus.METHOD_NOT_ALLOWED);
|
||||
ResponseEntity<Object> deleteById = client.exchange("http://localhost:8990/schemas/1", HttpMethod.DELETE,
|
||||
null, Object.class);
|
||||
schema.setDefinition(this.USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = this.client
|
||||
.postForEntity("http://localhost:8990/", schema, Schema.class);
|
||||
assertThat(response1.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
ResponseEntity<Object> deleteBySubjectFormatVersion = this.client.exchange(
|
||||
"http://localhost:8990/test/avro/v1", HttpMethod.DELETE, null,
|
||||
Object.class);
|
||||
assertThat(deleteBySubjectFormatVersion.getStatusCode())
|
||||
.isEqualTo(HttpStatus.METHOD_NOT_ALLOWED);
|
||||
ResponseEntity<Object> deleteBySubject = this.client.exchange(
|
||||
"http://localhost:8990/test", HttpMethod.DELETE, null, Object.class);
|
||||
assertThat(deleteBySubject.getStatusCode())
|
||||
.isEqualTo(HttpStatus.METHOD_NOT_ALLOWED);
|
||||
ResponseEntity<Object> deleteById = this.client.exchange(
|
||||
"http://localhost:8990/schemas/1", HttpMethod.DELETE, null, Object.class);
|
||||
assertThat(deleteById.getStatusCode()).isEqualTo(HttpStatus.METHOD_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
@@ -256,26 +260,27 @@ public class SchemaRegistryServerAvroTests {
|
||||
Schema v1 = new Schema();
|
||||
v1.setFormat("avro");
|
||||
v1.setSubject("test");
|
||||
v1.setDefinition(USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = client.postForEntity("http://localhost:8990/",
|
||||
v1, Schema.class);
|
||||
Assert.assertTrue(response1.getStatusCode().is2xxSuccessful());
|
||||
v1.setDefinition(this.USER_SCHEMA_V1);
|
||||
ResponseEntity<Schema> response1 = this.client
|
||||
.postForEntity("http://localhost:8990/", v1, Schema.class);
|
||||
assertThat(response1.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
|
||||
Schema v2 = new Schema();
|
||||
v2.setFormat("avro");
|
||||
v2.setSubject("test");
|
||||
v2.setDefinition(USER_SCHEMA_V2);
|
||||
v2.setDefinition(this.USER_SCHEMA_V2);
|
||||
|
||||
ResponseEntity<Schema> response2 = client.postForEntity("http://localhost:8990/",
|
||||
v2, Schema.class);
|
||||
Assert.assertTrue(response2.getStatusCode().is2xxSuccessful());
|
||||
ResponseEntity<Schema> response2 = this.client
|
||||
.postForEntity("http://localhost:8990/", v2, Schema.class);
|
||||
assertThat(response2.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
|
||||
ResponseEntity<List<Schema>> schemaResponse = client.exchange("http://localhost:8990/test/avro", HttpMethod.GET,
|
||||
null, new ParameterizedTypeReference<List<Schema>>() {
|
||||
ResponseEntity<List<Schema>> schemaResponse = this.client.exchange(
|
||||
"http://localhost:8990/test/avro", HttpMethod.GET, null,
|
||||
new ParameterizedTypeReference<List<Schema>>() {
|
||||
});
|
||||
|
||||
Assert.assertTrue(schemaResponse.getStatusCode().is2xxSuccessful());
|
||||
Assert.assertEquals(2, schemaResponse.getBody().size());
|
||||
assertThat(schemaResponse.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
assertThat(schemaResponse.getBody().size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,8 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
public class EntityScanningTests {
|
||||
|
||||
@Test
|
||||
public void testApplicationWithEmbeddedSchemaRegistryServerOutsideOfRootPackage() throws Exception {
|
||||
public void testApplicationWithEmbeddedSchemaRegistryServerOutsideOfRootPackage()
|
||||
throws Exception {
|
||||
final ConfigurableApplicationContext context = SpringApplication
|
||||
.run(CustomApplicationEmbeddingSchemaServer.class, "--server.port=0");
|
||||
context.close();
|
||||
@@ -38,5 +39,7 @@ public class EntityScanningTests {
|
||||
@EnableAutoConfiguration
|
||||
@EnableSchemaRegistryServer
|
||||
public static class CustomApplicationEmbeddingSchemaServer {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,8 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
public class EntityScanningTestsWithEntityScan {
|
||||
|
||||
@Test
|
||||
public void testApplicationWithEmbeddedSchemaRegistryServerOutsideOfRootPackage() throws Exception {
|
||||
public void testApplicationWithEmbeddedSchemaRegistryServerOutsideOfRootPackage()
|
||||
throws Exception {
|
||||
final ConfigurableApplicationContext context = SpringApplication
|
||||
.run(CustomApplicationEmbeddingSchemaServer.class, "--server.port=0");
|
||||
context.close();
|
||||
@@ -40,5 +41,7 @@ public class EntityScanningTestsWithEntityScan {
|
||||
@EnableSchemaRegistryServer
|
||||
@EntityScan(basePackages = "org.springframework.cloud.stream.schema.server.entityScanning.domain")
|
||||
public static class CustomApplicationEmbeddingSchemaServer {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,7 +33,7 @@ public class TestEntity {
|
||||
private String name;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
@@ -41,10 +41,11 @@ public class TestEntity {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user