return Change.ofRename(path, node.get("content").textValue());
return Change.ofRename(path, node.get("content").textValue());
return Change.ofRename(path, node.get("content").textValue());
break; case RENAME: result = Change.ofRename(path, content.asText()); break; case APPLY_JSON_PATCH:
@Test public void testEmptyCommitWithRedundantRenames() throws Exception { // Create a file to produce redundant changes. repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonUpserts[0]).join(); // Ensure redundant changes do not count as a valid change. assertThatThrownBy(() -> repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, Change.ofRename(jsonPaths[0], jsonPaths[1]), Change.ofRename(jsonPaths[1], jsonPaths[0])).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(RedundantChangeException.class); }
break; case RENAME: result = Change.ofRename(path, content.asText()); break; case APPLY_JSON_PATCH:
break; case RENAME: result = Change.ofRename(path, content.asText()); break; case APPLY_JSON_PATCH:
@Test public void testRenameWithConflict() throws Exception { // Create a file to produce redundant changes. repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonUpserts[0]).join(); // Attempt to rename to itself. assertThatThrownBy(() -> repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, Change.ofRename(jsonPaths[0], jsonPaths[0])).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(ChangeConflictException.class); }
@Test public void testRenameFailure() throws Exception { assertThatThrownBy(() -> repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonUpserts[0], jsonUpserts[1], Change.ofRename(jsonPaths[0], jsonPaths[1])).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(ChangeConflictException.class); // Renaming to its own path. repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonUpserts[0]).join(); assertThatThrownBy(() -> repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, Change.ofRename(jsonPaths[0], jsonPaths[0])).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(ChangeConflictException.class); // Renaming to its own path, when the file is not committed yet. assertThatThrownBy(() -> repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonUpserts[1], Change.ofRename(jsonPaths[1], jsonPaths[1])) .join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(ChangeConflictException.class); }
@Test public void testRecursiveRename() throws Exception { // Add some files under a directory. repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonUpserts).join(); assertThat(repo.find(HEAD, allPattern).join()).hasSize(jsonUpserts.length); // Rename the directory and ensure all files were moved. final String oldDir = prefix.substring(0, prefix.length() - 1); // Strip the trailing '/'. final String newDir = "/re_" + oldDir.substring(1) + "_named"; repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, Change.ofRename(oldDir, newDir)).join(); assertThat(repo.find(HEAD, allPattern).join()).isEmpty(); assertThat(repo.find(HEAD, newDir + "/**").join()).hasSize(jsonUpserts.length); // Add some files under a directory again. repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonUpserts).join(); assertThat(repo.find(HEAD, allPattern).join()).hasSize(jsonUpserts.length); // Attempt to rename the directory again, which should fail because the target directory exists now. assertThatThrownBy(() -> repo .commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, Change.ofRename(oldDir, newDir)).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(ChangeConflictException.class); }
@Test public void testRename() throws Exception { repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonUpserts[0]).join(); // Rename without content modification. repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, Change.ofRename(jsonPaths[0], jsonPaths[1])).join(); assertThat(repo.exists(HEAD, jsonPaths[0]).join()).isFalse(); assertThat(repo.exists(HEAD, jsonPaths[1]).join()).isTrue(); assertThat(repo.exists(HEAD, jsonPaths[2]).join()).isFalse(); assertThatJson(repo.get(HEAD, jsonPaths[1]).join().content()) .isEqualTo(jsonUpserts[0].content()); // Rename with content modification. repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, Change.ofRename(jsonPaths[1], jsonPaths[2]), Change.ofJsonPatch(jsonPaths[2], jsonPatches[1].content()), Change.ofJsonPatch(jsonPaths[2], jsonPatches[2].content())).join(); assertThat(repo.exists(HEAD, jsonPaths[0]).join()).isFalse(); assertThat(repo.exists(HEAD, jsonPaths[1]).join()).isFalse(); assertThat(repo.exists(HEAD, jsonPaths[2]).join()).isTrue(); assertThatJson(repo.get(HEAD, jsonPaths[2]).join().content()) .isEqualTo(jsonUpserts[2].content()); }
@Test public void testPreviewDiff() { final Map<String, Change<?>> changeMap = repo.previewDiff(HEAD, jsonUpserts[0]).join(); assertThat(changeMap).containsEntry(jsonPaths[0], jsonUpserts[0]); // Invalid patch assertThatThrownBy(() -> repo.previewDiff(HEAD, jsonPatches[1]).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(ChangeConflictException.class); // Invalid removal assertThatThrownBy(() -> repo.previewDiff(HEAD, Change.ofRemoval(jsonPaths[0])).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(ChangeConflictException.class); // Apply a series of changes final List<Change<?>> changes = Arrays.asList(jsonUpserts[0], jsonPatches[1], jsonPatches[2], Change.ofRename(jsonPaths[0], jsonPaths[1]), Change.ofRemoval(jsonPaths[1])); Map<String, Change<?>> returnedChangeMap = repo.previewDiff(HEAD, changes).join(); assertThat(returnedChangeMap).isEmpty(); assertThatThrownBy(() -> repo.previewDiff(new Revision(Integer.MAX_VALUE), changes).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(RevisionNotFoundException.class); assertThat(repo.previewDiff(new Revision(-1), Collections.emptyList()).join()).isEmpty(); // Test upsert on an existing path repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonPatches[0], jsonPatches[1]).join(); returnedChangeMap = repo.previewDiff(HEAD, jsonUpserts[0]).join(); assertThat(returnedChangeMap.get(jsonPaths[0]).type()).isEqualTo(ChangeType.APPLY_JSON_PATCH); }
@Test public void testDiff_rename() throws Exception { final CentralDogma client = rule.client(); final Revision rev1 = client.push(rule.project(), rule.repo1(), HEAD, "summary1", Change.ofTextUpsert("/bar.txt", "hello")).join().revision(); final Revision rev2 = client.push(rule.project(), rule.repo1(), HEAD, "summary2", Change.ofRename("/bar.txt", "/baz.txt")).join().revision(); assertThat(rev1.forward(1)).isEqualTo(rev2); assertThat(client.getDiff(rule.project(), rule.repo1(), rev1, rev2, Query.ofText("/bar.txt")).join()) .isEqualTo(Change.ofRemoval("/bar.txt")); } }
@Override protected com.linecorp.centraldogma.common.Change<?> doBackward(Change c) { switch (c.getType()) { case UPSERT_JSON: return com.linecorp.centraldogma.common.Change.ofJsonUpsert(c.getPath(), c.getContent()); case UPSERT_TEXT: return com.linecorp.centraldogma.common.Change.ofTextUpsert(c.getPath(), c.getContent()); case REMOVE: return com.linecorp.centraldogma.common.Change.ofRemoval(c.getPath()); case RENAME: return com.linecorp.centraldogma.common.Change.ofRename(c.getPath(), c.getContent()); case APPLY_JSON_PATCH: return com.linecorp.centraldogma.common.Change.ofJsonPatch(c.getPath(), c.getContent()); case APPLY_TEXT_PATCH: return com.linecorp.centraldogma.common.Change.ofTextPatch(c.getPath(), c.getContent()); } throw new Error(); }
@Override protected com.linecorp.centraldogma.common.Change<?> doBackward(Change c) { switch (c.getType()) { case UPSERT_JSON: return com.linecorp.centraldogma.common.Change.ofJsonUpsert(c.getPath(), c.getContent()); case UPSERT_TEXT: return com.linecorp.centraldogma.common.Change.ofTextUpsert(c.getPath(), c.getContent()); case REMOVE: return com.linecorp.centraldogma.common.Change.ofRemoval(c.getPath()); case RENAME: return com.linecorp.centraldogma.common.Change.ofRename(c.getPath(), c.getContent()); case APPLY_JSON_PATCH: return com.linecorp.centraldogma.common.Change.ofJsonPatch(c.getPath(), c.getContent()); case APPLY_TEXT_PATCH: return com.linecorp.centraldogma.common.Change.ofTextPatch(c.getPath(), c.getContent()); } throw new Error(); }
break; case RENAME: converted = unsafeCast(Change.ofRename(query.path(), r.getContent())); break; case APPLY_JSON_PATCH:
break; case RENAME: converted = unsafeCast(Change.ofRename(query.path(), r.getContent())); break; case APPLY_JSON_PATCH:
break; case RENAME: converted = unsafeCast(Change.ofRename(query.path(), r.getContent())); break; case APPLY_JSON_PATCH:
'}'); TestUtil.assertJsonConversion(Change.ofRename("/6", "/7"), Change.class, '{' + " \"type\": \"RENAME\"," +