@Override public Subject lookup(final String subjectName) { return repo.lookup(subjectName); }
@Override public Subject lookup(final String subjectName) { return repo.lookup(subjectName); }
private Subject getSubject(String subjectName) { Subject subject = repo.lookup(subjectName); if (null == subject) { throw new NotFoundException(MessageStrings.SUBJECT_DOES_NOT_EXIST_ERROR); } return subject; }
private Subject getSubject(String subjectName) { Subject subject = repo.lookup(subjectName); if (null == subject) { throw new NotFoundException(MessageStrings.SUBJECT_DOES_NOT_EXIST_ERROR); } return subject; }
@Override public Subject lookup(String subjectName) { return Subject.readOnly(repo.lookup(subjectName)); }
@Override public Subject lookup(String subjectName) { return Subject.readOnly(repo.lookup(subjectName)); }
@GET @Path("{subject}/config") public String subjectConfig(@HeaderParam("Accept") String mediaType, @PathParam("subject") String subject) { Subject s = repo.lookup(subject); if (null == s) { throw new NotFoundException(MessageStrings.SUBJECT_DOES_NOT_EXIST_ERROR); } Properties props = new Properties(); props.putAll(s.getConfig().asMap()); return getRenderer(mediaType).renderProperties(props, "Configuration of subject " + subject); }
@Override public Subject lookup(String subjectName) { Subject s = cache.lookup(subjectName); if (s == null) { return cache.add(repo.lookup(subjectName)); } return s; }
@GET @Path("{subject}/config") public String subjectConfig(@HeaderParam("Accept") String mediaType, @PathParam("subject") String subject) { Subject s = repo.lookup(subject); if (null == s) { throw new NotFoundException(MessageStrings.SUBJECT_DOES_NOT_EXIST_ERROR); } Properties props = new Properties(); props.putAll(s.getConfig().asMap()); return getRenderer(mediaType).renderProperties(props, "Configuration of subject " + subject); }
@Override public Subject lookup(String subjectName) { Subject s = cache.lookup(subjectName); if (s == null) { return cache.add(repo.lookup(subjectName)); } return s; }
/** * This retrieves mutable data, hence it is not cache-able and will always * result in a call to the underlying schema repo implementation. * * @param subjectName to get the config for * @return the requested subject's config, or null if the subject does not exist */ public SubjectConfig getConfig(SUBJECT subjectName) { Subject subject = repo.lookup(convertSubject.toString(subjectName)); if (subject != null) { return subject.getConfig(); } else { return null; // or throw exception? } }
/** * This retrieves mutable data, hence it is not cache-able and will always * result in a call to the underlying schema repo implementation. * * @param subjectName to get the config for * @return the requested subject's config, or null if the subject does not exist */ public SubjectConfig getConfig(SUBJECT subjectName) { Subject subject = repo.lookup(convertSubject.toString(subjectName)); if (subject != null) { return subject.getConfig(); } else { return null; // or throw exception? } }
/** * Returns all schemas in the given subject, serialized with * {@link org.schemarepo.RepositoryUtil#schemasToString(Iterable)} * * @param subject * The name of the subject * @return all schemas in the subject. Return a 404 Not Found if there is no such subject */ @GET @Path("{subject}/all") public Response allSchemaEntries(@HeaderParam("Accept") String mediaType, @PathParam("subject") String subject) { Subject s = repo.lookup(subject); if (null == s) { throw new NotFoundException(MessageStrings.SUBJECT_DOES_NOT_EXIST_ERROR); } Renderer renderer = getRenderer(mediaType); return Response.ok(renderer.renderSchemas(s.allEntries()), renderer.getMediaType()).build(); }
/** * Returns all schemas in the given subject, serialized with * {@link org.schemarepo.RepositoryUtil#schemasToString(Iterable)} * * @param subject * The name of the subject * @return all schemas in the subject. Return a 404 Not Found if there is no such subject */ @GET @Path("{subject}/all") public Response allSchemaEntries(@HeaderParam("Accept") String mediaType, @PathParam("subject") String subject) { Subject s = repo.lookup(subject); if (null == s) { throw new NotFoundException(MessageStrings.SUBJECT_DOES_NOT_EXIST_ERROR); } Renderer renderer = getRenderer(mediaType); return Response.ok(renderer.renderSchemas(s.allEntries()), renderer.getMediaType()).build(); }
Subject subject = repo.lookup(convertSubject.toString(subjectName)); if (subject != null) { SchemaEntry schemaEntry = subject.lookupById(convertId.toString(id));
@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); }
@Test public void testSubjectConfigs() { String testKey = "test.key"; String testVal = "test.val"; String testVal2 = "test.val2"; SubjectConfig conf = new SubjectConfig.Builder().set(testKey, testVal).build(); SubjectConfig conf2 = new SubjectConfig.Builder().set(testKey, testVal2).build(); // lookup a subject that does not exist, when none do Subject none = repo.lookup(CONF); Assert.assertNull("non-existent subject lookup should return null", none); // register a subject Subject sub = repo.register(CONF, conf); Assert.assertNotNull("failed to register subject: " + CONF, sub); // a duplicate register is idempotent; the result is the same Subject sub2 = repo.register(CONF, conf2); Assert.assertNotNull("failed to re-register subject: " + SUB, sub2); validateSubject(sub, sub2); // lookup subject that was just registered Subject sub3 = repo.lookup(CONF); validateSubject(sub, sub3); // lookup something that is not there Subject sub4 = repo.lookup(NOCONF); Assert.assertNull("subject should not exist", sub4); }
@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(); } }
Subject s1 = repo.lookup("sub1"); Assert.assertNotNull(s1);