@Test public void testEquals() { final Entry<Void> e = Entry.ofDirectory(new Revision(1), "/foo"); assertThat(e).isNotEqualTo(null); assertThat(e).isNotEqualTo(new Object()); assertThat(e).isEqualTo(e); }
@Test public void testFind_directory() throws Exception { // Will create the following directory structure: // // prefix -+- a // +- b -+- ba // +- bb // final Revision rev = repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, Change.ofTextUpsert(prefix + "a/file", ""), Change.ofTextUpsert(prefix + "b/ba/file", ""), Change.ofTextUpsert(prefix + "b/bb/file", "")).join(); final Entry<Void> a = Entry.ofDirectory(rev, prefix + 'a'); final Entry<Void> b = Entry.ofDirectory(rev, prefix + 'b'); final Entry<Void> b_ba = Entry.ofDirectory(rev, prefix + "b/ba"); final Entry<Void> b_bb = Entry.ofDirectory(rev, prefix + "b/bb"); // Recursive search final Collection<Entry<?>> entries = repo.find(HEAD, allPattern).join().entrySet().stream() .filter(e -> !e.getKey().endsWith("/file")) .map(Map.Entry::getValue).collect(Collectors.toList()); assertThat(entries).containsExactly(a, b, b_ba, b_bb); // Non-recursive search assertThat(repo.find(HEAD, prefix + '*').join().values()).containsExactly(a, b); // Single get assertThat(repo.find(HEAD, prefix + 'b').join().values()).containsExactly(b); }
public static com.linecorp.centraldogma.common.Entry<?> convert( com.linecorp.centraldogma.common.Revision revision, Entry entry) { switch (entry.getType()) { case JSON: try { final JsonNode value = Jackson.readTree(entry.getContent()); return com.linecorp.centraldogma.common.Entry.ofJson(revision, entry.getPath(), value); } catch (IOException e) { throw new UncheckedIOException(e); } case TEXT: return com.linecorp.centraldogma.common.Entry.ofText(revision, entry.getPath(), entry.getContent()); case DIRECTORY: return com.linecorp.centraldogma.common.Entry.ofDirectory(revision, entry.getPath()); default: throw new IllegalArgumentException("unsupported entry type: " + entry.getType()); } }
public static com.linecorp.centraldogma.common.Entry<?> convert( com.linecorp.centraldogma.common.Revision revision, Entry entry) { switch (entry.getType()) { case JSON: try { final JsonNode value = Jackson.readTree(entry.getContent()); return com.linecorp.centraldogma.common.Entry.ofJson(revision, entry.getPath(), value); } catch (IOException e) { throw new UncheckedIOException(e); } case TEXT: return com.linecorp.centraldogma.common.Entry.ofText(revision, entry.getPath(), entry.getContent()); case DIRECTORY: return com.linecorp.centraldogma.common.Entry.ofDirectory(revision, entry.getPath()); default: throw new IllegalArgumentException("unsupported entry type: " + entry.getType()); } }
@Test public void ofDirectory() throws Exception { final Entry<Void> e = Entry.ofDirectory(new Revision(1), "/"); assertThat(e.revision()).isEqualTo(new Revision(1)); assertThat(e.hasContent()).isFalse(); e.ifHasContent(unused -> fail()); assertThatThrownBy(e::content).isInstanceOf(IllegalStateException.class); assertThatThrownBy(e::contentAsJson).isInstanceOf(IllegalStateException.class); assertThatThrownBy(e::contentAsText).isInstanceOf(IllegalStateException.class); assertThatThrownBy(e::contentAsPrettyText).isInstanceOf(IllegalStateException.class); assertThatThrownBy(() -> e.contentAsJson(JsonNode.class)).isInstanceOf(IllegalStateException.class); // directory vs. directory final Entry<Void> e2 = Entry.ofDirectory(new Revision(1), "/"); assertThat(e).isEqualTo(e2); assertThat(e.hashCode()).isEqualTo(e2.hashCode()); assertThat(e).isNotEqualTo(Entry.ofDirectory(new Revision(2), "/")); assertThat(e).isNotEqualTo(Entry.ofDirectory(new Revision(1), "/foo")); // directory vs. text file final Entry<String> e3 = Entry.ofText(new Revision(1), "/a.txt", "foo"); assertThat(e).isNotEqualTo(e3); assertThat(e.hashCode()).isNotEqualTo(e3.hashCode()); // directory vs. JSON file final Entry<JsonNode> e4 = Entry.ofJson(new Revision(1), "/a.json", "{ \"foo\": \"bar\" }"); assertThat(e).isNotEqualTo(e4); assertThat(e.hashCode()).isNotEqualTo(e4.hashCode()); }
return Collections.singletonMap(pathPattern, Entry.ofDirectory(normRevision, "/")); if (matches) { result.put(path, Entry.ofDirectory(normRevision, path));
return Collections.singletonMap(pathPattern, Entry.ofDirectory(normRevision, "/")); if (matches) { result.put(path, Entry.ofDirectory(normRevision, path));
return Collections.singletonMap(pathPattern, Entry.ofDirectory(normRevision, "/")); if (matches) { result.put(path, Entry.ofDirectory(normRevision, path));
assertThat(client.getFiles(projName, REPO_FOO, rev2, "/target/**").join().values()) .containsExactlyInAnyOrder(expectedSecondMirrorState, Entry.ofDirectory(rev2, "/target/first"), Entry.ofText(rev2, "/target/first/light.txt", "26-Aug-2014\n"));
final Entry<Void> e4 = Entry.ofDirectory(new Revision(1), "/foo"); assertThat(e).isNotEqualTo(e4); assertThat(e.hashCode()).isNotEqualTo(e4.hashCode());
break; case DIRECTORY: converted = unsafeCast(Entry.ofDirectory(normRev, query.path())); break; default:
break; case DIRECTORY: converted = unsafeCast(Entry.ofDirectory(normRev, query.path())); break; default:
break; case DIRECTORY: converted = unsafeCast(Entry.ofDirectory(normRev, query.path())); break; default:
assertThat(client.getFiles(projName, REPO_FOO, rev3, "/**").join().values()) .containsExactlyInAnyOrder(expectedSecondMirrorState, Entry.ofDirectory(rev3, "/first"), Entry.ofText(rev3, "/first/light.txt", "26-Aug-2014\n"), Entry.ofDirectory(rev3, "/second"), Entry.ofJson(rev3, "/second/son.json", "{\"release_date\": \"21-Mar-2014\"}"));
@Test public void ofJson() throws Exception { final Entry<JsonNode> e = Entry.ofJson(new Revision(1), "/a.json", "{ \"foo\": \"bar\" }"); assertThat(e.revision()).isEqualTo(new Revision(1)); assertThat(e.hasContent()).isTrue(); e.ifHasContent(content -> assertThatJson(content).isEqualTo("{ \"foo\": \"bar\" }")); assertThatJson(e.content()).isEqualTo("{ \"foo\": \"bar\" }"); assertThat(e.contentAsText()).isEqualTo("{\"foo\":\"bar\"}"); assertThat(e.contentAsPrettyText()).isEqualTo("{\n \"foo\": \"bar\"\n}"); assertThat(e.content()).isSameAs(e.contentAsJson()); assertThat(e.content()).isEqualTo(e.contentAsJson(JsonNode.class)); // JSON file vs. JSON file final Entry<JsonNode> e2 = Entry.ofJson(new Revision(1), "/a.json", "{ \"foo\": \"bar\" }"); assertThat(e).isEqualTo(e2); assertThat(e.hashCode()).isEqualTo(e2.hashCode()); assertThat(e).isNotEqualTo(Entry.ofJson(new Revision(2), "/a.json", "{ \"foo\": \"bar\" }")); assertThat(e).isNotEqualTo(Entry.ofJson(new Revision(1), "/b.json", "{ \"foo\": \"bar\" }")); assertThat(e).isNotEqualTo(Entry.ofJson(new Revision(1), "/a.json", "null")); // JSON file vs. text file final Entry<String> e3 = Entry.ofText(new Revision(1), "/a.json", "{\"foo\":\"bar\"}"); assertThat(e).isNotEqualTo(e3); assertThat(e.hashCode()).isNotEqualTo(e3.hashCode()); // JSON file vs. directory final Entry<Void> e4 = Entry.ofDirectory(new Revision(1), "/foo"); assertThat(e).isNotEqualTo(e4); assertThat(e.hashCode()).isNotEqualTo(e4.hashCode()); }
break; case DIRECTORY: converted = unsafeCast(Entry.ofDirectory(revision, query.path())); break; default:
break; case DIRECTORY: converted = unsafeCast(Entry.ofDirectory(revision, query.path())); break; default:
break; case DIRECTORY: converted = unsafeCast(Entry.ofDirectory(revision, query.path())); break; default: