@GET @Path("/{schemaName}/branches") @Timed @Produces(MediaType.APPLICATION_JSON) public Response getSchemaBranches(@PathParam("schemaName") String schemaName, @Context SecurityContext securityContext) { try { Collection<SchemaBranch> schemaBranches = schemaRegistryClient.getSchemaBranches(schemaName); LOG.info("Schema branches for schema [{}] : {}", schemaName, schemaBranches); List<String> schemaBranchNames = Collections.emptyList(); if (schemaBranches != null && !schemaBranches.isEmpty()) { schemaBranchNames = schemaBranches.stream().map(SchemaBranch::getName).collect(Collectors.toList()); } return WSUtils.respondEntities(schemaBranchNames, OK); } catch (SchemaNotFoundException e) { LOG.error("Schema not found with name: [{}]", schemaName, e); throw EntityNotFoundException.byName(schemaName); } catch (Exception e) { throw new RuntimeException(e); } }
@Test (expected = SchemaNotFoundException.class) public void getAllBranchesForInvalidSchemaName() throws SchemaNotFoundException { schemaRegistryClient.getSchemaBranches(testNameRule.getMethodName()); }
@Test public void getAllBranches() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException { SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), SchemaCompatibility.NONE); SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc"); SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId()); SchemaIdVersion masterSchemaIdVersion2 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device-incompat.avsc"); SchemaBranch schemaBranch2 = addSchemaBranch("BRANCH2", schemaMetadata, masterSchemaIdVersion2.getSchemaVersionId()); Set<String> actualSchemaBranches = schemaRegistryClient.getSchemaBranches(schemaMetadata.getName()).stream().map(branch -> branch.getName()).collect(Collectors.toSet()); Set<String> expectedSchemaBranches = new HashSet<>(Lists.newArrayList("MASTER", schemaBranch1.getName(), schemaBranch2.getName())); Assert.assertTrue(SetUtils.isEqualSet(actualSchemaBranches, expectedSchemaBranches)); }
@Test public void deleteSchemaBranch() throws SchemaNotFoundException, SchemaBranchAlreadyExistsException, IOException, InvalidSchemaException, IncompatibleSchemaException, SchemaBranchNotFoundException, InvalidSchemaBranchDeletionException { SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), SchemaCompatibility.NONE); SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc"); SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId()); addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc"); addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-compat.avsc"); Assert.assertTrue(schemaRegistryClient.getSchemaBranches(schemaMetadata.getName()).size() == 2); schemaRegistryClient.deleteSchemaBranch(schemaBranch1.getId()); Collection<SchemaVersionInfo> masterSchemaVersionInfos = schemaRegistryClient.getAllVersions(schemaMetadata.getName()); Assert.assertTrue(masterSchemaVersionInfos.size() == 1); Assert.assertTrue(schemaRegistryClient.getSchemaBranches(schemaMetadata.getName()).size() == 1); }