TollboothSchemaStoreClient implements SchemaStoreClient { @Override public SchemaVersion registerSchema(String name, Schema schema) throws InvalidSchemaException, ServiceException, UnknownRoadException { return registerSchema(name, schema, OptionalInt.empty()); } @Autowired  TollboothSchemaStoreClient(@Value("#{store}") Map<String, Road> store, PatchSetEmitter modificationEmitter); @Override Optional<SchemaVersion> getSchema(String name, int version); @Override Optional<SchemaVersion> getActiveSchema(String name, int version); @Override Optional<SchemaVersion> getLatestActiveSchema(String name); @Override SchemaVersion registerSchema(String name, Schema schema); @Override SchemaVersion registerSchema(String name, Schema schema, int version); @Override Map<Integer, SchemaVersion> getAllSchemaVersions(String name); @Override Map<Integer, SchemaVersion> getActiveSchemaVersions(String name); @Override void deleteSchemaVersion(String name, int version);  }
@Test public void registerSchema_one() throws Exception { SchemaVersion registerSchema = client.registerSchema("road1", schema1); assertThat(registerSchema, is(schemaVersion1)); Map<Integer, SchemaVersion> schemas = store.get("road1").getSchemas(); assertThat(schemas.size(), is(1)); assertThat(schemas.values().contains(schemaVersion1), is(true)); }
@Test public void registerSchema_many() throws Exception { client.registerSchema("road1", schema1); client.registerSchema("road1", schema2); client.registerSchema("road1", schema3); Map<Integer, SchemaVersion> schemas = store.get("road1").getSchemas(); assertThat(schemas.size(), is(3)); assertThat(schemas.get(1), is(schemaVersion1)); assertThat(schemas.get(2), is(schemaVersion2)); assertThat(schemas.get(3), is(schemaVersion3)); }
@Test(expected = IllegalArgumentException.class) public void registerSchema_invalidCompatibilityMode() throws Exception { road1.setCompatibilityMode("ThisIsNotValid"); client.registerSchema("road1", schema1); }
@Test public void registerSchema_defaultCompatibilityModeWouldFail() throws Exception { road1.setCompatibilityMode(SchemaCompatibility.CAN_BE_READ_BY_LATEST.name()); client.registerSchema("road1", schema3); client.registerSchema("road1", schema4); Map<Integer, SchemaVersion> schemas = store.get("road1").getSchemas(); assertThat(schemas.size(), is(2)); }
@Test public void registerSchema_specifyVersion() throws Exception { SchemaVersion registerSchema = client.registerSchema("road1", schema2, 2); assertThat(registerSchema, is(schemaVersion2)); Map<Integer, SchemaVersion> schemas = store.get("road1").getSchemas(); assertThat(schemas.size(), is(1)); assertThat(schemas.get(2), is(schemaVersion2)); }
@Test(expected = InvalidSchemaVersionException.class) public void registerSchema_specifyVersion_InvalidSchemaVersionException() throws Exception { road1.setSchemas(Collections.singletonMap(1, schemaVersion1)); client.registerSchema("road1", schema1, 1); }
@Test(expected = InvalidSchemaException.class) public void registerSchema_incompatible() throws Exception { client.registerSchema("road1", schema1); client.registerSchema("road1", schema2); client.registerSchema("road1", schema3); client.registerSchema("road1", schema4); }
@Test(expected = InvalidSchemaException.class) public void registerSchema_notARecord() throws Exception { client.registerSchema("road1", SchemaBuilder.builder().booleanType()); }
@Test(expected = UnknownRoadException.class) public void registerSchema_fails_when_road_isDeleted() throws Exception { road1.setDeleted(true); client.registerSchema("road1", schema1); }
@Test(expected = InvalidPiiAnnotationException.class) public void addPiiToExistingFieldFails() throws Exception { Schema newSchema = SchemaBuilder .record("r") .fields() .name("f") .prop("sensitivity", "PII") .type(SchemaBuilder.builder().stringType()) .noDefault() .endRecord(); Schema currentSchema = SchemaBuilder .record("r") .fields() .name("f") .type(SchemaBuilder.builder().stringType()) .noDefault() .endRecord(); client.registerSchema("road1", currentSchema); client.registerSchema("road1", newSchema); }