@Test public void getFile_path() throws Exception { doAnswer(invocation -> { final AsyncMethodCallback<com.linecorp.centraldogma.internal.thrift.Revision> callback = invocation.getArgument(3); callback.onComplete(new com.linecorp.centraldogma.internal.thrift.Revision(1, 0)); return null; }).when(iface).normalizeRevision(any(), any(), any(), any()); doAnswer(invocation -> { final AsyncMethodCallback<GetFileResult> callback = invocation.getArgument(4); callback.onComplete(new GetFileResult(TEntryType.TEXT, "content")); return null; }).when(iface).getFile(any(), any(), any(), any(), any()); assertThat(client.getFile("project", "repo", new Revision(1), Query.ofText("/a.txt")).get()) .isEqualTo(Entry.ofText(new Revision(1), "/a.txt", "content")); verify(iface).getFile(eq("project"), eq("repo"), any(), any(), any()); }
@Test public void getFile() throws Exception { doAnswer(invocation -> { final AsyncMethodCallback<com.linecorp.centraldogma.internal.thrift.Revision> callback = invocation.getArgument(3); callback.onComplete(new com.linecorp.centraldogma.internal.thrift.Revision(1, 0)); return null; }).when(iface).normalizeRevision(any(), any(), any(), any()); doAnswer(invocation -> { final AsyncMethodCallback<GetFileResult> callback = invocation.getArgument(4); callback.onComplete(new GetFileResult(TEntryType.TEXT, "content")); return null; }).when(iface).getFile(any(), any(), any(), any(), any()); assertThat(client.getFile("project", "repo", new Revision(1), Query.ofText("/a.txt")).get()) .isEqualTo(Entry.ofText(new Revision(1), "/a.txt", "content")); verify(iface).getFile(eq("project"), eq("repo"), any(), any(), any()); }
@Test public void watchFile() throws Exception { doAnswer(invocation -> { AsyncMethodCallback<WatchFileResult> callback = invocation.getArgument(5); callback.onComplete(new WatchFileResult().setRevision(new TRevision(42)) .setType(TEntryType.TEXT) .setContent("foo")); return null; }).when(iface).watchFile(any(), any(), any(), any(), anyLong(), any()); assertThat(client.watchFile("project", "repo", new Revision(1), Query.ofText("/a.txt"), 100).get()) .isEqualTo(Entry.ofText(new Revision(42), "/a.txt", "foo")); verify(iface).watchFile(eq("project"), eq("repo"), any(), any(), eq(100L), any()); }
@Test public void getFiles() throws Exception { doAnswer(invocation -> { final AsyncMethodCallback<com.linecorp.centraldogma.internal.thrift.Revision> callback = invocation.getArgument(3); callback.onComplete(new com.linecorp.centraldogma.internal.thrift.Revision(1, 0)); return null; }).when(iface).normalizeRevision(any(), any(), any(), any()); doAnswer(invocation -> { final AsyncMethodCallback<List<TEntry>> callback = invocation.getArgument(4); final TEntry entry = new TEntry("/b.txt", TEntryType.TEXT); entry.setContent("world"); callback.onComplete(ImmutableList.of(entry)); return null; }).when(iface).getFiles(anyString(), anyString(), any(), anyString(), any()); assertThat(client.getFiles("project", "repo", new Revision(1), "path").get()) .isEqualTo(ImmutableMap.of("/b.txt", Entry.ofText(new Revision(1), "/b.txt", "world"))); verify(iface).getFiles(anyString(), anyString(), any(), anyString(), any()); }
@Test public void testToString() { assertThat(Entry.ofText(new Revision(1), "/a.txt", "a").toString()).isNotEmpty(); } }
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 @SuppressWarnings("unchecked") public void identityQuery() { final Repository repo = setMockNames(newCachingRepo()); final Query<String> query = Query.ofText("/baz.txt"); final Entry<String> result = Entry.ofText(new Revision(10), "/baz.txt", "qux"); final Map<String, Entry<?>> entries = ImmutableMap.of("/baz.txt", result); doReturn(new Revision(10)).when(delegateRepo).normalizeNow(new Revision(10)); doReturn(new Revision(10)).when(delegateRepo).normalizeNow(HEAD); // Uncached when(delegateRepo.find(any(), any(), any())).thenReturn(completedFuture(entries)); assertThat(repo.get(HEAD, query).join()).isEqualTo(result); verify(delegateRepo).find(new Revision(10), "/baz.txt", FIND_ONE_WITH_CONTENT); verifyNoMoreInteractions(delegateRepo); // Cached clearInvocations(delegateRepo); assertThat(repo.get(HEAD, query).join()).isEqualTo(result); assertThat(repo.get(new Revision(10), query).join()).isEqualTo(result); verify(delegateRepo, never()).find(any(), any(), any()); verifyNoMoreInteractions(delegateRepo); }
@Test public void find() { final Repository repo = setMockNames(newCachingRepo()); final Map<String, Entry<?>> entries = ImmutableMap.of("/baz.txt", Entry.ofText(new Revision(10), "/baz.txt", "qux")); doReturn(new Revision(10)).when(delegateRepo).normalizeNow(new Revision(10)); doReturn(new Revision(10)).when(delegateRepo).normalizeNow(HEAD); // Uncached when(delegateRepo.find(any(), any(), any())).thenReturn(completedFuture(entries)); assertThat(repo.find(HEAD, "/**", ImmutableMap.of()).join()).isEqualTo(entries); verify(delegateRepo).find(new Revision(10), "/**", ImmutableMap.of()); verifyNoMoreInteractions(delegateRepo); // Cached clearInvocations(delegateRepo); assertThat(repo.find(HEAD, "/**", ImmutableMap.of()).join()).isEqualTo(entries); assertThat(repo.find(new Revision(10), "/**", ImmutableMap.of()).join()).isEqualTo(entries); verify(delegateRepo, never()).find(any(), any(), any()); verifyNoMoreInteractions(delegateRepo); }
@Test public void ofText() throws Exception { final Entry<String> e = Entry.ofText(new Revision(1), "/a.txt", "foo"); assertThat(e.revision()).isEqualTo(new Revision(1)); assertThat(e.hasContent()).isTrue(); assertThat(Entry.ofText(new Revision(1), "/a.txt", "null").contentAsJson()) .isEqualTo(Jackson.nullNode); assertThat(Entry.ofText(new Revision(1), "/a.txt", "null").contentAsJson(JsonNode.class)) .isEqualTo(Jackson.nullNode); final Entry<String> e2 = Entry.ofText(new Revision(1), "/a.txt", "foo"); assertThat(e).isEqualTo(e2); assertThat(e.hashCode()).isEqualTo(e2.hashCode()); assertThat(e).isNotEqualTo(Entry.ofText(new Revision(2), "/a.txt", "foo")); assertThat(e).isNotEqualTo(Entry.ofText(new Revision(1), "/b.txt", "foo")); assertThat(e).isNotEqualTo(Entry.ofText(new Revision(1), "/a.txt", "bar"));
@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()); }
.containsExactlyInAnyOrder(expectedSecondMirrorState, Entry.ofDirectory(rev2, "/target/first"), Entry.ofText(rev2, "/target/first/light.txt", "26-Aug-2014\n"));
converted = unsafeCast(Entry.ofText(normRev, query.path(), r.getContent())); break; case DIRECTORY:
converted = unsafeCast(Entry.ofText(normRev, query.path(), r.getContent())); break; case DIRECTORY:
converted = unsafeCast(Entry.ofText(normRev, query.path(), r.getContent())); break; case DIRECTORY:
@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()); }
converted = unsafeCast(Entry.ofText(revision, query.path(), r.getContent())); break; case DIRECTORY:
converted = unsafeCast(Entry.ofText(revision, query.path(), r.getContent())); break; case DIRECTORY:
converted = unsafeCast(Entry.ofText(revision, query.path(), r.getContent())); break; case DIRECTORY:
final Entry<String> expectedAlphabets = Entry.ofText( headRev, "/alphabets.txt",