@Test void mergeFiles() throws Exception { doAnswer(invocation -> { final AsyncMethodCallback<MergedEntry> callback = invocation.getArgument(4); callback.onComplete(new MergedEntry(new TRevision(1), TEntryType.JSON, "{\"foo\": \"bar\"}", ImmutableList.of("/a.json", "/b.json"))); return null; }).when(iface).mergeFiles(any(), any(), any(), any(), any()); assertThat(client.mergeFiles("project", "repo", new Revision(1), MergeQuery.ofJson(ImmutableList.of(MergeSource.ofOptional("/a.json"), MergeSource.ofRequired("/b.json")))) .get()) .isEqualTo(com.linecorp.centraldogma.common.MergedEntry.of( new Revision(1), EntryType.JSON, Jackson.readTree("{\"foo\": \"bar\"}"), ImmutableList.of("/a.json", "/b.json"))); verify(iface).mergeFiles(eq("project"), eq("repo"), any(), any(), any()); }
@Override public <T> CompletableFuture<MergedEntry<T>> mergeFiles(String projectName, String repositoryName, Revision revision, MergeQuery<T> mergeQuery) { final CompletableFuture<com.linecorp.centraldogma.internal.thrift.MergedEntry> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(revision, "revision"); requireNonNull(mergeQuery, "mergeQuery"); client.mergeFiles(projectName, repositoryName, RevisionConverter.TO_DATA.convert(revision), MergeQueryConverter.TO_DATA.convert(mergeQuery), callback); }); return future.thenApply(entry -> { final EntryType entryType = EntryConverter.convertEntryType(entry.getType()); assert entryType != null; switch (entryType) { case JSON: try { @SuppressWarnings("unchecked") final MergedEntry<T> converted = (MergedEntry<T>) MergedEntry.of( RevisionConverter.TO_MODEL.convert(entry.revision), entryType, Jackson.readTree(entry.content), entry.paths); return converted; } catch (IOException e) { throw new CentralDogmaException( "failed to parse the content: " + entry.content, e); } default: throw new Error("unsupported entry type: " + entryType); } }); }
LegacyCentralDogma extends AbstractCentralDogma { @Override public <T> CompletableFuture<MergedEntry<T>> mergeFiles(String projectName, String repositoryName, Revision revision, MergeQuery<T> mergeQuery) { final CompletableFuture<com.linecorp.centraldogma.internal.thrift.MergedEntry> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(revision, "revision"); requireNonNull(mergeQuery, "mergeQuery"); client.mergeFiles(projectName, repositoryName, RevisionConverter.TO_DATA.convert(revision), MergeQueryConverter.TO_DATA.convert(mergeQuery), callback); }); return future.thenApply(entry -> { final EntryType entryType = EntryConverter.convertEntryType(entry.getType()); assert entryType != null; switch (entryType) { case JSON: try { @SuppressWarnings("unchecked") final MergedEntry<T> converted = (MergedEntry<T>) MergedEntry.of( RevisionConverter.TO_MODEL.convert(entry.revision), entryType, Jackson.readTree(entry.content), entry.paths); return converted; } catch (IOException e) { throw new CentralDogmaException( "failed to parse the content: " + entry.content, e); } default: throw new Error("unsupported entry type: " + entryType); } }); } }
LegacyCentralDogma extends AbstractCentralDogma { @Override public <T> CompletableFuture<MergedEntry<T>> mergeFiles(String projectName, String repositoryName, Revision revision, MergeQuery<T> mergeQuery) { final CompletableFuture<com.linecorp.centraldogma.internal.thrift.MergedEntry> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(revision, "revision"); requireNonNull(mergeQuery, "mergeQuery"); client.mergeFiles(projectName, repositoryName, RevisionConverter.TO_DATA.convert(revision), MergeQueryConverter.TO_DATA.convert(mergeQuery), callback); }); return future.thenApply(entry -> { final EntryType entryType = EntryConverter.convertEntryType(entry.getType()); assert entryType != null; switch (entryType) { case JSON: try { @SuppressWarnings("unchecked") final MergedEntry<T> converted = (MergedEntry<T>) MergedEntry.of( RevisionConverter.TO_MODEL.convert(entry.revision), entryType, Jackson.readTree(entry.content), entry.paths); return converted; } catch (IOException e) { throw new CentralDogmaException( "failed to parse the content: " + entry.content, e); } default: throw new Error("unsupported entry type: " + entryType); } }); } LegacyCentralDogma(ScheduledExecutorService executor, CentralDogmaService.AsyncIface client); }
LegacyCentralDogma extends AbstractCentralDogma { @Override public <T> CompletableFuture<MergedEntry<T>> mergeFiles(String projectName, String repositoryName, Revision revision, MergeQuery<T> mergeQuery) { final CompletableFuture<com.linecorp.centraldogma.internal.thrift.MergedEntry> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(revision, "revision"); requireNonNull(mergeQuery, "mergeQuery"); client.mergeFiles(projectName, repositoryName, RevisionConverter.TO_DATA.convert(revision), MergeQueryConverter.TO_DATA.convert(mergeQuery), callback); }); return future.thenApply(entry -> { final EntryType entryType = EntryConverter.convertEntryType(entry.getType()); assert entryType != null; switch (entryType) { case JSON: try { @SuppressWarnings("unchecked") final MergedEntry<T> converted = (MergedEntry<T>) MergedEntry.of( RevisionConverter.TO_MODEL.convert(entry.revision), entryType, Jackson.readTree(entry.content), entry.paths); return converted; } catch (IOException e) { throw new CentralDogmaException( "failed to parse the content: " + entry.content, e); } default: throw new Error("unsupported entry type: " + entryType); } }); } LegacyCentralDogma(ScheduledExecutorService executor, CentralDogmaService.AsyncIface client); @Override CompletableFuture<Void> createProject(String projectName); @Override CompletableFuture<Void> removeProject(String projectName); @Override CompletableFuture<Void> purgeProject(String projectName); @Override CompletableFuture<Void> unremoveProject(String projectName); @Override CompletableFuture<Set<String>> listProjects(); @Override CompletableFuture<Set<String>> listRemovedProjects(); @Override CompletableFuture<Void> createRepository(String projectName, String repositoryName); @Override CompletableFuture<Void> removeRepository(String projectName, String repositoryName); @Override CompletableFuture<Void> purgeRepository(String projectName, String repositoryName); @Override CompletableFuture<Void> unremoveRepository(String projectName, String repositoryName); @Override CompletableFuture<Map<String, RepositoryInfo>> listRepositories(String projectName); @Override CompletableFuture<Set<String>> listRemovedRepositories(String projectName); @Override CompletableFuture<Revision> normalizeRevision(String projectName, String repositoryName,
                                                         Revision revision); @Override CompletableFuture<Map<String, EntryType>> listFiles(String projectName, String repositoryName,
                                                               Revision revision, String pathPattern); @Override CompletableFuture<Entry<T>> getFile(String projectName, String repositoryName,
                                                   Revision revision, Query<T> query); @Override CompletableFuture<Map<String, Entry<?>>> getFiles(String projectName, String repositoryName,
                                                             Revision revision, String pathPattern); @Override CompletableFuture<MergedEntry<T>> mergeFiles(String projectName, String repositoryName,
                                                            Revision revision, MergeQuery<T> mergeQuery); @Override CompletableFuture<List<Commit>> getHistory(String projectName,
                                                      String repositoryName,
                                                      Revision from,
                                                      Revision to,
                                                      String pathPattern); @Override CompletableFuture<Change<T>> getDiff(String projectName, String repositoryName,
                                                    Revision from, Revision to, Query<T> query); @Override CompletableFuture<List<Change<?>>> getDiffs(String projectName, String repositoryName,
                                                       Revision from, Revision to, String pathPattern); @Override CompletableFuture<List<Change<?>>> getPreviewDiffs(String projectName, String repositoryName,
                                                              Revision baseRevision,
                                                              Iterable<? extends Change<?>> changes); @Override CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision,
                                              String summary, String detail, Markup markup,
                                              Iterable<? extends Change<?>> changes); @Override CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision,
                                              Author author, String summary, String detail, Markup markup,
                                              Iterable<? extends Change<?>> changes); @Override CompletableFuture<Revision> watchRepository(String projectName, String repositoryName,
                                                       Revision lastKnownRevision,
                                                       String pathPattern,
                                                       long timeoutMillis); @Override CompletableFuture<Entry<T>> watchFile(String projectName, String repositoryName,
                                                     Revision lastKnownRevision, Query<T> query,
                                                     long timeoutMillis); }
LegacyCentralDogma extends AbstractCentralDogma { @Override public <T> CompletableFuture<MergedEntry<T>> mergeFiles(String projectName, String repositoryName, Revision revision, MergeQuery<T> mergeQuery) { final CompletableFuture<com.linecorp.centraldogma.internal.thrift.MergedEntry> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(revision, "revision"); requireNonNull(mergeQuery, "mergeQuery"); client.mergeFiles(projectName, repositoryName, RevisionConverter.TO_DATA.convert(revision), MergeQueryConverter.TO_DATA.convert(mergeQuery), callback); }); return future.thenApply(entry -> { final EntryType entryType = EntryConverter.convertEntryType(entry.getType()); assert entryType != null; switch (entryType) { case JSON: try { @SuppressWarnings("unchecked") final MergedEntry<T> converted = (MergedEntry<T>) MergedEntry.of( RevisionConverter.TO_MODEL.convert(entry.revision), entryType, Jackson.readTree(entry.content), entry.paths); return converted; } catch (IOException e) { throw new CentralDogmaException( "failed to parse the content: " + entry.content, e); } default: throw new Error("unsupported entry type: " + entryType); } }); } LegacyCentralDogma(ScheduledExecutorService executor, CentralDogmaService.AsyncIface client); @Override CompletableFuture<Void> createProject(String projectName); @Override CompletableFuture<Void> removeProject(String projectName); @Override CompletableFuture<Void> purgeProject(String projectName); @Override CompletableFuture<Void> unremoveProject(String projectName); @Override CompletableFuture<Set<String>> listProjects(); @Override CompletableFuture<Set<String>> listRemovedProjects(); @Override CompletableFuture<Void> createRepository(String projectName, String repositoryName); @Override CompletableFuture<Void> removeRepository(String projectName, String repositoryName); @Override CompletableFuture<Void> purgeRepository(String projectName, String repositoryName); @Override CompletableFuture<Void> unremoveRepository(String projectName, String repositoryName); @Override CompletableFuture<Map<String, RepositoryInfo>> listRepositories(String projectName); @Override CompletableFuture<Set<String>> listRemovedRepositories(String projectName); @Override CompletableFuture<Revision> normalizeRevision(String projectName, String repositoryName,
                                                         Revision revision); @Override CompletableFuture<Map<String, EntryType>> listFiles(String projectName, String repositoryName,
                                                               Revision revision, String pathPattern); @Override CompletableFuture<Entry<T>> getFile(String projectName, String repositoryName,
                                                   Revision revision, Query<T> query); @Override CompletableFuture<Map<String, Entry<?>>> getFiles(String projectName, String repositoryName,
                                                             Revision revision, String pathPattern); @Override CompletableFuture<MergedEntry<T>> mergeFiles(String projectName, String repositoryName,
                                                            Revision revision, MergeQuery<T> mergeQuery); @Override CompletableFuture<List<Commit>> getHistory(String projectName,
                                                      String repositoryName,
                                                      Revision from,
                                                      Revision to,
                                                      String pathPattern); @Override CompletableFuture<Change<T>> getDiff(String projectName, String repositoryName,
                                                    Revision from, Revision to, Query<T> query); @Override CompletableFuture<List<Change<?>>> getDiffs(String projectName, String repositoryName,
                                                       Revision from, Revision to, String pathPattern); @Override CompletableFuture<List<Change<?>>> getPreviewDiffs(String projectName, String repositoryName,
                                                              Revision baseRevision,
                                                              Iterable<? extends Change<?>> changes); @Override CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision,
                                              String summary, String detail, Markup markup,
                                              Iterable<? extends Change<?>> changes); @Override CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision,
                                              Author author, String summary, String detail, Markup markup,
                                              Iterable<? extends Change<?>> changes); @Override CompletableFuture<Revision> watchRepository(String projectName, String repositoryName,
                                                       Revision lastKnownRevision,
                                                       String pathPattern,
                                                       long timeoutMillis); @Override CompletableFuture<Entry<T>> watchFile(String projectName, String repositoryName,
                                                     Revision lastKnownRevision, Query<T> query,
                                                     long timeoutMillis);  }