@Override public SchemaEntry register(String schema) throws SchemaValidationException { return delegate.register(schema); }
@Test public void testSuccessfulValidation() throws SchemaValidationException { Subject accept = repo.register(ACCEPT, new SubjectConfig.Builder() .addValidator(ACCEPT_VALIDATOR).build()); SchemaEntry foo = accept.registerIfLatest(FOO, null); Assert.assertNotNull("failed to register schema", foo); SchemaEntry bar = accept.registerIfLatest(BAR, foo); Assert.assertNotNull("failed to register schema", bar); SchemaEntry none = accept.registerIfLatest("nothing", null); Assert.assertNull(none); SchemaEntry baz = accept.register(BAZ); Assert.assertNotNull("failed to register schema", baz); }
@Override public SchemaEntry register(String schema) throws SchemaValidationException { return delegate.register(schema); }
/** * Register a schema with a subject * * @param subject * The subject name to register the schema in * @param schema * The schema to register * @return A 200 response with the corresponding id if successful, a 403 * forbidden response if the schema fails validation, or a 404 not * found response if the subject does not exist */ @PUT @Path("{subject}/register") @Consumes(MediaType.TEXT_PLAIN) public Response addSchema(@PathParam("subject") String subject, String schema) { try { return Response.ok(getSubject(subject).register(schema).getId()).build(); } catch (SchemaValidationException e) { return Response.status(Status.FORBIDDEN).build(); } }
/** * Register a schema with a subject * * @param subject * The subject name to register the schema in * @param schema * The schema to register * @return A 200 response with the corresponding id if successful, * a 403 forbidden response with exception message if the schema fails validation, * or a 404 not found response if the subject does not exist */ @PUT @Path("{subject}/register") @Consumes(MediaType.TEXT_PLAIN) public Response addSchema(@PathParam("subject") String subject, String schema) { try { return Response.ok(getSubject(subject).register(schema).getId()).build(); } catch (SchemaValidationException e) { return Response.status(Status.FORBIDDEN).entity(e.getMessage()).build(); } }
@Test(expected=IllegalStateException.class) public void testCannotRegisterSchema() throws SchemaValidationException { repo.register(FOO, null); readOnlyRepo.lookup(FOO).register(null); }
@Test public void testConfig() { Properties props = new Properties(); props.setProperty(Config.REPO_CLASS, InMemoryRepository.class.getName()); props.put(Config.VALIDATOR_PREFIX + "rejectAll", Reject.class.getName()); ConfigModule module = new ConfigModule(props); Injector injector = Guice.createInjector(module); Repository repo = injector.getInstance(Repository.class); Subject rejects = repo.register("rejects", new SubjectConfig.Builder() .addValidator("rejectAll").build()); boolean threw = false; try { rejects.register("stuff"); } catch (SchemaValidationException se) { threw = true; } Assert.assertTrue(threw); }
SchemaEntry schemaEntry = subject.register(convertSchema.toString(schema)); id = convertId.fromString(schemaEntry.getId());
@Test public void testAllEntriesMultiLineSchema() throws Exception { String endOfLine = System.getProperty("line.separator"); String multiLineSchema1 = "first line" + endOfLine + "second line"; String multiLineSchema2 = "first line" + endOfLine + "second line" + endOfLine; repo.register("sub1", null).register(multiLineSchema1); repo.register("sub1", null).register(multiLineSchema2); Subject s1 = repo.lookup("sub1"); Assert.assertNotNull(s1); Iterable<SchemaEntry> allEntries = s1.allEntries(); boolean foundSub1 = false, foundSub2 = false; for (SchemaEntry entry: allEntries) { if (entry.getSchema().equals(multiLineSchema1)) { foundSub1 = true; } else if (entry.getSchema().equals(multiLineSchema2)) { foundSub2 = true; } } Assert.assertTrue("Check that allEntries() returns proper multi-line schemas", foundSub1 && foundSub2); }
SchemaEntry schemaEntry = subject.register(convertSchema.toString(schema)); id = convertId.fromString(schemaEntry.getId());
@Test(expected=SchemaValidationException.class) public void testCannotRegister() throws SchemaValidationException { Subject reject = repo.register(REJECT, new SubjectConfig.Builder() .addValidator(ValidatorFactory.REJECT_VALIDATOR).build()); reject.register(FOO); }
@Test public void testValidation() { SubjectConfig conf = new SubjectConfig.Builder().addValidator(ValidatorFactory.REJECT_VALIDATOR).build(); // lookup a subject that does not exist, when none do Subject none = repo.lookup(VALIDATING); Assert.assertNull("non-existent subject lookup should return null", none); // register a subject that should reject all schemas Subject sub = repo.register(VALIDATING, conf); Assert.assertNotNull("failed to register subject: " + VALIDATING, sub); boolean threw = false; try { sub.register("stuff"); } catch (SchemaValidationException e) { threw = true; } Assert.assertTrue("must throw a SchemaValidationException", threw); }
@Test public void testWriteCloseRead() throws Exception { try { repo.register("sub1", null).register("sc1"); repo.register("sub2", null).register("sc2"); repo.register("sub2", null).register("sc3"); } finally { repo.close(); } // Calling close() and createRepository() is like bouncing the repo, to ensure its state persists. repo = createRepository(); try { Subject s1 = repo.lookup("sub1"); Assert.assertNotNull(s1); Subject s2 = repo.lookup("sub2"); Assert.assertNotNull(s2); SchemaEntry e1 = s1.lookupBySchema("sc1"); Assert.assertNotNull(e1); Assert.assertEquals("sc1", e1.getSchema()); SchemaEntry e2 = s2.lookupBySchema("sc2"); Assert.assertNotNull(e2); Assert.assertEquals("sc2", e2.getSchema()); SchemaEntry e3 = s2.lookupBySchema("sc3"); Assert.assertNotNull(e3); Assert.assertEquals("sc3", e3.getSchema()); } finally { repo.close(); } }
hasSub); SchemaEntry foo = sub.register(FOO); boolean foundfoo = false; for (SchemaEntry s : readOnlySubject.allEntries()) {