mergeSourceBuilder.add(MergeSource.ofRequired(value)); } else if ("optional_path".equals(key)) { mergeSourceBuilder.add(MergeSource.ofOptional(value)); } else if ("jsonpath".equals(key)) { jsonPathsBuilder.add(value);
private static List<com.linecorp.centraldogma.common.MergeSource> convertMergeSources( MergeQuery mergeQuery) { return mergeQuery.mergeSources .stream() .map(mergeSource -> { if (mergeSource.isIsOptional()) { return com.linecorp.centraldogma.common.MergeSource.ofOptional(mergeSource.getPath()); } return com.linecorp.centraldogma.common.MergeSource.ofRequired(mergeSource.getPath()); }) .collect(toImmutableList()); }
mergeSourceBuilder.add(MergeSource.ofRequired(value)); } else if ("optional_path".equals(key)) { mergeSourceBuilder.add(MergeSource.ofOptional(value)); } else if ("jsonpath".equals(key)) { jsonPathsBuilder.add(value);
@Test public 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()); }
@Test public void convert() throws Exception { final ServiceRequestContext ctx = mock(ServiceRequestContext.class); final String queryString = "path=/foo.json" + '&' + "pa%22th=/foo1.json" + '&' + "optional_path=/foo2.json" + '&' + "path=/foo3.json" + '&' + "jsonpath=$.a" + '&' + "revision=9999"; when(ctx.query()).thenReturn(queryString); @SuppressWarnings("unchecked") final MergeQuery<JsonNode> mergeQuery = (MergeQuery<JsonNode>) converter.convertRequest( ctx, mock(AggregatedHttpMessage.class), null); assertThat(mergeQuery).isEqualTo( MergeQuery.ofJsonPath( ImmutableList.of(MergeSource.ofRequired("/foo.json"), MergeSource.ofOptional("/foo2.json"), MergeSource.ofRequired("/foo3.json")), ImmutableList.of("$.a"))); } }