@Override public String renderSchemaEntry(SchemaEntry schemaEntry, boolean requestForLatest) { return requestForLatest ? schemaEntry.toString() : schemaEntry.getSchema(); }
@Override public synchronized SchemaEntry add(SchemaEntry entry) { if (null == entry) { return entry; } SchemaEntry prior = schemaToEntry.putIfAbsent(entry.getSchema(), entry); if (null != prior) { entry = prior; } idToSchema.put(entry.getId(), entry); schemasInOrder.push(entry); return entry; }
@Override public String renderSchemaEntry(SchemaEntry schemaEntry, boolean requestForLatest) { return requestForLatest ? schemaEntry.toString() : schemaEntry.getSchema(); }
@Override public synchronized SchemaEntry add(SchemaEntry entry) { if (null == entry) { return entry; } SchemaEntry prior = schemaToEntry.putIfAbsent(entry.getSchema(), entry); if (null != prior) { entry = prior; } idToSchema.put(entry.getId(), entry); schemasInOrder.push(entry); return entry; }
/** * Encode {@link SchemaEntry} objects into a {@link String} for use by * {@link #schemasFromString(String)} * * @param allEntries * the SchemaEntry objects to encode * @return The {@link SchemaEntry} objects encoded as a String */ public static String schemasToString(Iterable<SchemaEntry> allEntries) { StringBuilder sb = new StringBuilder(); boolean scheamWithNewLine = false; for (SchemaEntry s : allEntries) { if (s.getSchema().contains("\n")) { scheamWithNewLine = true; } sb.append(s.toString()).append("\n"); } if (scheamWithNewLine) { return new StringBuilder() .append(MessageStrings.SCHEMA_WITH_NEWLINE_ERROR) .append(sb).toString(); } else { return sb.toString(); } }
/** * Encode {@link SchemaEntry} objects into a {@link String} for use by * {@link #schemasFromString(String)} * * @param allEntries * the SchemaEntry objects to encode * @return The {@link SchemaEntry} objects encoded as a String */ public static String schemasToString(Iterable<SchemaEntry> allEntries) { StringBuilder sb = new StringBuilder(); boolean scheamWithNewLine = false; for (SchemaEntry s : allEntries) { if (s.getSchema().contains("\n")) { scheamWithNewLine = true; } sb.append(s.toString()).append("\n"); } if (scheamWithNewLine) { return new StringBuilder() .append(MessageStrings.SCHEMA_WITH_NEWLINE_ERROR) .append(sb).toString(); } else { return sb.toString(); } }
SchemaEntry schemaEntry = subject.lookupById(convertId.toString(id)); if (schemaEntry != null) { schema = convertSchema.fromString(schemaEntry.getSchema());
SchemaEntry schemaEntry = subject.lookupById(convertId.toString(id)); if (schemaEntry != null) { schema = convertSchema.fromString(schemaEntry.getSchema());
schema = convertSchema.fromString(schemaEntry.getSchema());
schema = convertSchema.fromString(schemaEntry.getSchema());
@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); }
private void validateSchemaEntry(String expectedSchema, SchemaEntry foo) { Assert.assertNotNull("Failed to create SchemaEntry with schema: " + expectedSchema, foo); Assert.assertEquals("SchemaEntry does not have expected schema value", expectedSchema, foo.getSchema()); Assert.assertNotNull("SchemaEntry does not have a valid id", foo.getId()); Assert.assertFalse("SchemaEntry has an empty id", foo.getId().isEmpty()); }
@Test public void testGetters() { String id = "id"; String sc = "sc"; SchemaEntry entry = new SchemaEntry(id, sc); Assert.assertEquals(id, entry.getId()); Assert.assertEquals(sc, entry.getSchema()); }
Assert.assertEquals(multiLineSchema1, schemaEntry1ById.getSchema()); Assert.assertEquals(multiLineSchema1, schemaEntry1BySchema.getSchema()); Assert.assertEquals(multiLineSchema2, schemaEntry2ById.getSchema()); Assert.assertEquals(multiLineSchema2, schemaEntry2BySchema.getSchema()); } finally { repo.close();
@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(); } }
SchemaEntry resultfoo = subject.lookupBySchema(foo.getSchema()); Assert.assertEquals("lookup by Schema did not return same result", foo, resultfoo);