@Override int weigh(Map<String, Change<?>> value) { int weight = 0; weight += pathPattern.length(); for (Change<?> e : value.values()) { weight += e.path().length(); final String content = e.contentAsText(); if (content != null) { weight += content.length(); } } return weight; }
@Override int weigh(Map<String, Change<?>> value) { int weight = 0; weight += pathPattern.length(); for (Change<?> e : value.values()) { weight += e.path().length(); final String content = e.contentAsText(); if (content != null) { weight += content.length(); } } return weight; }
@Override int weigh(Map<String, Change<?>> value) { int weight = 0; weight += pathPattern.length(); for (Change<?> e : value.values()) { weight += e.path().length(); final String content = e.contentAsText(); if (content != null) { weight += content.length(); } } return weight; }
@Override int weigh(Change<?> value) { int weight = 0; weight += query.path().length(); for (String e : query.expressions()) { weight += e.length(); } weight += value.path().length(); final String content = value.contentAsText(); if (content != null) { weight += content.length(); } return weight; }
@Override int weigh(Change<?> value) { int weight = 0; weight += query.path().length(); for (String e : query.expressions()) { weight += e.length(); } weight += value.path().length(); final String content = value.contentAsText(); if (content != null) { weight += content.length(); } return weight; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Change)) { return false; } final Change<?> that = (Change<?>) o; if (type != that.type()) { return false; } if (!path.equals(that.path())) { return false; } return Objects.equals(content, that.content()); }
@Override int weigh(Change<?> value) { int weight = 0; weight += query.path().length(); for (String e : query.expressions()) { weight += e.length(); } weight += value.path().length(); final String content = value.contentAsText(); if (content != null) { weight += content.length(); } return weight; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Change)) { return false; } final Change<?> that = (Change<?>) o; if (type != that.type()) { return false; } if (!path.equals(that.path())) { return false; } return Objects.equals(content, that.content()); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Change)) { return false; } final Change<?> that = (Change<?>) o; if (type != that.type()) { return false; } if (!path.equals(that.path())) { return false; } return Objects.equals(content, that.content()); }
public static <T> ChangeDto<T> convert(Change<T> change) { requireNonNull(change, "change"); return new ChangeDto<>(change.path(), change.type(), change.content()); }
public static <T> ChangeDto<T> convert(Change<T> change) { requireNonNull(change, "change"); return new ChangeDto<>(change.path(), change.type(), change.content()); }
public static <T> ChangeDto<T> convert(Change<T> change) { requireNonNull(change, "change"); return new ChangeDto<>(change.path(), change.type(), change.content()); }
static ChangeDto convert(Change<?> change) { final ChangeDto dto = new ChangeDto(); dto.setPath(change.path()); dto.setType(change.type().name()); dto.setContent(change.contentAsText()); return dto; }
static ChangeDto convert(Change<?> change) { final ChangeDto dto = new ChangeDto(); dto.setPath(change.path()); dto.setType(change.type().name()); dto.setContent(change.contentAsText()); return dto; }
static ChangeDto convert(Change<?> change) { final ChangeDto dto = new ChangeDto(); dto.setPath(change.path()); dto.setType(change.type().name()); dto.setContent(change.contentAsText()); return dto; }
@Test public void testMultipleChanges() throws Exception { final List<Change<?>> changes = new ArrayList<>(); Collections.addAll(changes, jsonUpserts); for (int i = 1; i < jsonPatches.length; i++) { changes.add(jsonPatches[i]); } repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, changes).join(); final Map<String, Entry<?>> entries = repo.find(HEAD, allPattern).join(); assertThat(entries).hasSize(jsonUpserts.length); for (int i = 0; i < jsonUpserts.length; i++) { final Change<?> c = jsonUpserts[i]; assertThat(entries).containsKey(c.path()); if (i == 0) { // We have patched the first upsert to make it identical to the last upsert. assertThatJson(entries.get(c.path()).content()) .isEqualTo(jsonUpserts[jsonUpserts.length - 1].content()); } else { assertThatJson(entries.get(c.path()).content()).isEqualTo(c.content()); } } }
/** * Run a sequence of modification on the same path, validate the diff after each push. */ @Test public void testDiff_modify() throws Exception { final String jsonNodePath = jsonPatches[0].path(); final String textNodePath = textPatches[0].path(); // initial commit Revision prevRevision = repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonPatches[0], textPatches[0]).join(); for (int i = 1; i < NUM_ITERATIONS; i++) { final Revision currRevision = repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonPatches[i], textPatches[i]).join(); final Map<String, Change<?>> changes = repo.diff(prevRevision, currRevision, allPattern).join(); assertThat(changes).hasSize(2) .containsEntry(jsonNodePath, jsonPatches[i]) .containsEntry(textNodePath, textPatches[i]); final Map<String, Change<?>> changesRelative = repo.diff(HEAD.backward(1), HEAD, allPattern).join(); assertThat(changesRelative).isEqualTo(changes); prevRevision = currRevision; } }
/** * Test exception handling when invalid arguments are given. */ @Test public void testDiff_invalidParameters() throws Exception { final String path = jsonPatches[0].path(); final Revision revision1 = repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonPatches[0]).join(); final Revision revision2 = repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, jsonPatches[1]).join(); assertThat(repo.diff(revision1, revision2, "non_existing_path").join()).isEmpty(); assertThatThrownBy(() -> repo.diff(revision1, revision2, (String) null).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(NullPointerException.class); assertThatThrownBy(() -> repo.diff(null, revision2, path).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(NullPointerException.class); assertThatThrownBy(() -> repo.diff(revision1, new Revision(revision2.major() + 1), path).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(RevisionNotFoundException.class); assertThatThrownBy(() -> repo.diff(new Revision(revision2.major() + 1), revision2, path).join()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(RevisionNotFoundException.class); }
@Override protected Change doForward(com.linecorp.centraldogma.common.Change<?> value) { final Change change = new Change(value.path(), convertChangeType(value.type())); switch (change.getType()) { case UPSERT_JSON: case APPLY_JSON_PATCH: try { change.setContent(Jackson.writeValueAsString(value.content())); } catch (JsonProcessingException e) { throw new ChangeFormatException("failed to read a JSON tree", e); } break; case UPSERT_TEXT: case APPLY_TEXT_PATCH: case RENAME: change.setContent((String) value.content()); break; case REMOVE: break; } return change; }
@Override protected Change doForward(com.linecorp.centraldogma.common.Change<?> value) { final Change change = new Change(value.path(), convertChangeType(value.type())); switch (change.getType()) { case UPSERT_JSON: case APPLY_JSON_PATCH: try { change.setContent(Jackson.writeValueAsString(value.content())); } catch (JsonProcessingException e) { throw new ChangeFormatException("failed to read a JSON tree", e); } break; case UPSERT_TEXT: case APPLY_TEXT_PATCH: case RENAME: change.setContent((String) value.content()); break; case REMOVE: break; } return change; }