@Test void diffFile() throws Exception { doAnswer(invocation -> { final AsyncMethodCallback<DiffFileResult> callback = invocation.getArgument(5); callback.onComplete(new DiffFileResult(ChangeType.UPSERT_TEXT, "some_text")); return null; }).when(iface).diffFile(any(), any(), any(), any(), any(), any()); assertThat(client.getDiff("project", "repo", new Revision(1), new Revision(3), Query.ofText("/a.txt")).get()) .isEqualTo(Change.ofTextUpsert("/a.txt", "some_text")); verify(iface).diffFile(eq("project"), eq("repo"), any(), any(), any(), any()); }
@Override public <T> CompletableFuture<Change<T>> getDiff(String projectName, String repositoryName, Revision from, Revision to, Query<T> query) { final CompletableFuture<DiffFileResult> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(query, "query"); client.diffFile(projectName, repositoryName, RevisionConverter.TO_DATA.convert(from), RevisionConverter.TO_DATA.convert(to), QueryConverter.TO_DATA.convert(query), callback); }); return future.thenApply(r -> { if (r == null) { return null; } final Change<T> converted; switch (r.getType()) { case UPSERT_JSON: converted = unsafeCast(Change.ofJsonUpsert(query.path(), r.getContent())); break; case UPSERT_TEXT: converted = unsafeCast(Change.ofTextUpsert(query.path(), r.getContent())); break; case REMOVE: converted = unsafeCast(Change.ofRemoval(query.path())); break; case RENAME: converted = unsafeCast(Change.ofRename(query.path(), r.getContent())); break; case APPLY_JSON_PATCH: converted = unsafeCast(Change.ofJsonPatch(query.path(), r.getContent())); break; case APPLY_TEXT_PATCH: converted = unsafeCast(Change.ofTextPatch(query.path(), r.getContent())); break; default: throw new Error("unknown change type: " + r.getType()); } return converted; }); }
LegacyCentralDogma extends AbstractCentralDogma { @Override public <T> CompletableFuture<Change<T>> getDiff(String projectName, String repositoryName, Revision from, Revision to, Query<T> query) { final CompletableFuture<DiffFileResult> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(query, "query"); client.diffFile(projectName, repositoryName, RevisionConverter.TO_DATA.convert(from), RevisionConverter.TO_DATA.convert(to), QueryConverter.TO_DATA.convert(query), callback); }); return future.thenApply(r -> { if (r == null) { return null; } final Change<T> converted; switch (r.getType()) { case UPSERT_JSON: converted = unsafeCast(Change.ofJsonUpsert(query.path(), r.getContent())); break; case UPSERT_TEXT: converted = unsafeCast(Change.ofTextUpsert(query.path(), r.getContent())); break; case REMOVE: converted = unsafeCast(Change.ofRemoval(query.path())); break; case RENAME: converted = unsafeCast(Change.ofRename(query.path(), r.getContent())); break; case APPLY_JSON_PATCH: converted = unsafeCast(Change.ofJsonPatch(query.path(), r.getContent())); break; case APPLY_TEXT_PATCH: converted = unsafeCast(Change.ofTextPatch(query.path(), r.getContent())); break; default: throw new Error("unknown change type: " + r.getType()); } return converted; }); } }
LegacyCentralDogma extends AbstractCentralDogma { @Override public <T> CompletableFuture<Change<T>> getDiff(String projectName, String repositoryName, Revision from, Revision to, Query<T> query) { final CompletableFuture<DiffFileResult> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(query, "query"); client.diffFile(projectName, repositoryName, RevisionConverter.TO_DATA.convert(from), RevisionConverter.TO_DATA.convert(to), QueryConverter.TO_DATA.convert(query), callback); }); return future.thenApply(r -> { if (r == null) { return null; } final Change<T> converted; switch (r.getType()) { case UPSERT_JSON: converted = unsafeCast(Change.ofJsonUpsert(query.path(), r.getContent())); break; case UPSERT_TEXT: converted = unsafeCast(Change.ofTextUpsert(query.path(), r.getContent())); break; case REMOVE: converted = unsafeCast(Change.ofRemoval(query.path())); break; case RENAME: converted = unsafeCast(Change.ofRename(query.path(), r.getContent())); break; case APPLY_JSON_PATCH: converted = unsafeCast(Change.ofJsonPatch(query.path(), r.getContent())); break; case APPLY_TEXT_PATCH: converted = unsafeCast(Change.ofTextPatch(query.path(), r.getContent())); break; default: throw new Error("unknown change type: " + r.getType()); } return converted; }); } LegacyCentralDogma(ScheduledExecutorService executor, CentralDogmaService.AsyncIface client); }
LegacyCentralDogma extends AbstractCentralDogma { @Override public <T> CompletableFuture<Change<T>> getDiff(String projectName, String repositoryName, Revision from, Revision to, Query<T> query) { final CompletableFuture<DiffFileResult> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(query, "query"); client.diffFile(projectName, repositoryName, RevisionConverter.TO_DATA.convert(from), RevisionConverter.TO_DATA.convert(to), QueryConverter.TO_DATA.convert(query), callback); }); return future.thenApply(r -> { if (r == null) { return null; } final Change<T> converted; switch (r.getType()) { case UPSERT_JSON: converted = unsafeCast(Change.ofJsonUpsert(query.path(), r.getContent())); break; case UPSERT_TEXT: converted = unsafeCast(Change.ofTextUpsert(query.path(), r.getContent())); break; case REMOVE: converted = unsafeCast(Change.ofRemoval(query.path())); break; case RENAME: converted = unsafeCast(Change.ofRename(query.path(), r.getContent())); break; case APPLY_JSON_PATCH: converted = unsafeCast(Change.ofJsonPatch(query.path(), r.getContent())); break; case APPLY_TEXT_PATCH: converted = unsafeCast(Change.ofTextPatch(query.path(), r.getContent())); break; default: throw new Error("unknown change type: " + r.getType()); } return converted; }); } 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<Change<T>> getDiff(String projectName, String repositoryName, Revision from, Revision to, Query<T> query) { final CompletableFuture<DiffFileResult> future = run(callback -> { validateProjectAndRepositoryName(projectName, repositoryName); requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(query, "query"); client.diffFile(projectName, repositoryName, RevisionConverter.TO_DATA.convert(from), RevisionConverter.TO_DATA.convert(to), QueryConverter.TO_DATA.convert(query), callback); }); return future.thenApply(r -> { if (r == null) { return null; } final Change<T> converted; switch (r.getType()) { case UPSERT_JSON: converted = unsafeCast(Change.ofJsonUpsert(query.path(), r.getContent())); break; case UPSERT_TEXT: converted = unsafeCast(Change.ofTextUpsert(query.path(), r.getContent())); break; case REMOVE: converted = unsafeCast(Change.ofRemoval(query.path())); break; case RENAME: converted = unsafeCast(Change.ofRename(query.path(), r.getContent())); break; case APPLY_JSON_PATCH: converted = unsafeCast(Change.ofJsonPatch(query.path(), r.getContent())); break; case APPLY_TEXT_PATCH: converted = unsafeCast(Change.ofTextPatch(query.path(), r.getContent())); break; default: throw new Error("unknown change type: " + r.getType()); } return converted; }); } 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);  }