static Commit newCommit(Author author, long when, String jsonString) { requireNonNull(author, "author"); when = when / 1000L * 1000L; // Drop the milliseconds try { final JsonNode jsonNode = Jackson.readTree(jsonString); final String summary = Jackson.textValue(jsonNode.get(FIELD_NAME_SUMMARY), ""); final String detail = Jackson.textValue(jsonNode.get(FIELD_NAME_DETAIL), ""); final Markup markup; switch (Jackson.textValue(jsonNode.get(FIELD_NAME_MARKUP), "")) { case "plaintext": markup = Markup.PLAINTEXT; break; case "markdown": markup = Markup.MARKDOWN; break; default: markup = Markup.UNKNOWN; } final Revision revision = new Revision(Jackson.textValue(jsonNode.get(FIELD_NAME_REVISION), "")); return new Commit(revision, author, when, summary, detail, markup); } catch (Exception e) { throw new StorageException("failed to create a Commit", e); } }
static Commit newCommit(Author author, long when, String jsonString) { requireNonNull(author, "author"); when = when / 1000L * 1000L; // Drop the milliseconds try { final JsonNode jsonNode = Jackson.readTree(jsonString); final String summary = Jackson.textValue(jsonNode.get(FIELD_NAME_SUMMARY), ""); final String detail = Jackson.textValue(jsonNode.get(FIELD_NAME_DETAIL), ""); final Markup markup; switch (Jackson.textValue(jsonNode.get(FIELD_NAME_MARKUP), "")) { case "plaintext": markup = Markup.PLAINTEXT; break; case "markdown": markup = Markup.MARKDOWN; break; default: markup = Markup.UNKNOWN; } final Revision revision = new Revision(Jackson.textValue(jsonNode.get(FIELD_NAME_REVISION), "")); return new Commit(revision, author, when, summary, detail, markup); } catch (Exception e) { throw new StorageException("failed to create a Commit", e); } }
static Commit newCommit(Author author, long when, String jsonString) { requireNonNull(author, "author"); when = when / 1000L * 1000L; // Drop the milliseconds try { final JsonNode jsonNode = Jackson.readTree(jsonString); final String summary = Jackson.textValue(jsonNode.get(FIELD_NAME_SUMMARY), ""); final String detail = Jackson.textValue(jsonNode.get(FIELD_NAME_DETAIL), ""); final Markup markup; switch (Jackson.textValue(jsonNode.get(FIELD_NAME_MARKUP), "")) { case "plaintext": markup = Markup.PLAINTEXT; break; case "markdown": markup = Markup.MARKDOWN; break; default: markup = Markup.UNKNOWN; } final Revision revision = new Revision(Jackson.textValue(jsonNode.get(FIELD_NAME_REVISION), "")); return new Commit(revision, author, when, summary, detail, markup); } catch (Exception e) { throw new StorageException("failed to create a Commit", e); } }
private Repository newCachingRepo() { when(delegateRepo.history(INIT, INIT, Repository.ALL_PATH, 1)).thenReturn(completedFuture( ImmutableList.of(new Commit(INIT, SYSTEM, "", "", Markup.PLAINTEXT)))); final Repository cachingRepo = new CachingRepository(delegateRepo, new RepositoryCache("maximumSize=1000")); // Verify that CachingRepository calls delegateRepo.history() once to retrieve the initial commit. verify(delegateRepo, times(1)).history(INIT, INIT, Repository.ALL_PATH, 1); verifyNoMoreInteractions(delegateRepo); clearInvocations(delegateRepo); return cachingRepo; }
@Override protected com.linecorp.centraldogma.common.Commit doBackward(Commit commit) { final Markup markup = Markup.valueOf(commit.getDetail().getMarkup().name()); return new com.linecorp.centraldogma.common.Commit( RevisionConverter.TO_MODEL.convert(commit.getRevision()), AuthorConverter.TO_MODEL.convert(commit.getAuthor()), Instant.parse(commit.getTimestamp()).toEpochMilli(), commit.getSummary(), commit.getDetail().getContent(), markup); } }
@Override protected com.linecorp.centraldogma.common.Commit doBackward(Commit commit) { final Markup markup = Markup.valueOf(commit.getDetail().getMarkup().name()); return new com.linecorp.centraldogma.common.Commit( RevisionConverter.TO_MODEL.convert(commit.getRevision()), AuthorConverter.TO_MODEL.convert(commit.getAuthor()), Instant.parse(commit.getTimestamp()).toEpochMilli(), commit.getSummary(), commit.getDetail().getContent(), markup); } }
@Test public void getHistory() throws Exception { doAnswer(invocation -> { final AsyncMethodCallback<List<TCommit>> callback = invocation.getArgument(5); callback.onComplete(ImmutableList.of(new TCommit( new TRevision(1), new TAuthor("name", "name@sample.com"), TIMESTAMP, "summary", new Comment("detail").setMarkup(TMarkup.PLAINTEXT), ImmutableList.of(new TChange("/a.txt", ChangeType.UPSERT_TEXT).setContent("content"))))); return null; }).when(iface).getHistory(any(), any(), any(), any(), any(), any()); assertThat(client.getHistory("project", "repo", new Revision(1), new Revision(3), "path").get()) .isEqualTo(ImmutableList.of(new Commit(new Revision(1), new Author("name", "name@sample.com"), Instant.parse(TIMESTAMP).toEpochMilli(), "summary", "detail", Markup.PLAINTEXT))); verify(iface).getHistory(eq("project"), eq("repo"), any(), any(), eq("path"), any()); }
@Test public void history() { final Repository repo = setMockNames(newCachingRepo()); final List<Commit> commits = ImmutableList.of( new Commit(new Revision(3), SYSTEM, "third", "", Markup.MARKDOWN), new Commit(new Revision(3), SYSTEM, "second", "", Markup.MARKDOWN), new Commit(new Revision(3), SYSTEM, "first", "", Markup.MARKDOWN)); doReturn(new RevisionRange(3, 1)).when(delegateRepo).normalizeNow(HEAD, INIT); doReturn(new RevisionRange(3, 1)).when(delegateRepo).normalizeNow(HEAD, new Revision(-3)); doReturn(new RevisionRange(3, 1)).when(delegateRepo).normalizeNow(new Revision(3), new Revision(-3)); doReturn(new RevisionRange(3, 1)).when(delegateRepo).normalizeNow(new Revision(3), INIT); // Uncached when(delegateRepo.history(any(), any(), any(), anyInt())).thenReturn(completedFuture(commits)); assertThat(repo.history(HEAD, INIT, "/**", Integer.MAX_VALUE).join()).isEqualTo(commits); verify(delegateRepo).history(new Revision(3), INIT, "/**", 3); verifyNoMoreInteractions(delegateRepo); // Cached clearInvocations(delegateRepo); assertThat(repo.history(HEAD, new Revision(-3), "/**", 3).join()).isEqualTo(commits); assertThat(repo.history(HEAD, INIT, "/**", 4).join()).isEqualTo(commits); assertThat(repo.history(new Revision(3), new Revision(-3), "/**", 5).join()).isEqualTo(commits); assertThat(repo.history(new Revision(3), INIT, "/**", 6).join()).isEqualTo(commits); verify(delegateRepo, never()).history(any(), any(), any(), anyInt()); verifyNoMoreInteractions(delegateRepo); }
@Test public void listRepositories() throws Exception { doAnswer(invocation -> { final AsyncMethodCallback<List<Repository>> callback = invocation.getArgument(1); final Repository repository = new Repository("repo").setHead( new TCommit(new TRevision(42), new TAuthor("hitchhiker", "arthur@dent.com"), "1978-03-08T00:00:00Z", "The primary phrase", new Comment(""), null)); callback.onComplete(ImmutableList.of(repository)); return null; }).when(iface).listRepositories(any(), any()); assertThat(client.listRepositories("project").get()).isEqualTo(ImmutableMap.of( "repo", new RepositoryInfo( "repo", new Commit(new Revision(42), new Author("hitchhiker", "arthur@dent.com"), Instant.parse("1978-03-08T00:00:00Z").toEpochMilli(), "The primary phrase", "", Markup.PLAINTEXT)))); verify(iface).listRepositories(eq("project"), any()); }