Skip to content

Commit e384b9d

Browse files
committed
Add ITs
1 parent 5ba66fe commit e384b9d

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

it/src/test/java/com/linecorp/centraldogma/it/GetFileTest.java

+44
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,25 @@
1717
package com.linecorp.centraldogma.it;
1818

1919
import static com.linecorp.centraldogma.testing.internal.ExpectedExceptionAppender.assertThatThrownByWithExpectedException;
20+
import static java.nio.charset.StandardCharsets.UTF_8;
2021
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
2122
import static org.assertj.core.api.Assertions.assertThat;
2223
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2324

25+
import java.io.File;
26+
import java.io.IOException;
27+
import java.nio.file.Files;
2428
import java.util.concurrent.CompletionException;
2529

30+
import org.junit.jupiter.api.Nested;
31+
import org.junit.jupiter.api.Test;
2632
import org.junit.jupiter.api.extension.RegisterExtension;
2733
import org.junit.jupiter.params.ParameterizedTest;
2834
import org.junit.jupiter.params.provider.EnumSource;
2935

36+
import com.fasterxml.jackson.core.JsonParseException;
3037
import com.fasterxml.jackson.databind.JsonNode;
38+
import com.google.common.collect.ImmutableList;
3139

3240
import com.linecorp.centraldogma.client.CentralDogma;
3341
import com.linecorp.centraldogma.common.Change;
@@ -38,6 +46,7 @@
3846
import com.linecorp.centraldogma.common.QueryExecutionException;
3947
import com.linecorp.centraldogma.common.RepositoryNotFoundException;
4048
import com.linecorp.centraldogma.common.Revision;
49+
import com.linecorp.centraldogma.internal.Json5;
4150

4251
class GetFileTest {
4352

@@ -100,4 +109,39 @@ void invalidProject(ClientType clientType) throws Exception {
100109
Query.ofJsonPath("/test/test2.json", "$.non_exist_path")).join())
101110
.isInstanceOf(CompletionException.class).hasCauseInstanceOf(ProjectNotFoundException.class);
102111
}
112+
113+
@Nested
114+
class GetFileJson5Test {
115+
116+
final String JSON5_CONTENTS = new String(
117+
Files.readAllBytes(new File(GetFileJson5Test.class.getClassLoader().getResource(
118+
"com/linecorp/centraldogma/it/import/test1.json5").getPath()).toPath()), UTF_8);
119+
120+
GetFileJson5Test() throws IOException {}
121+
122+
@Test
123+
void getJson5() throws JsonParseException {
124+
final CentralDogma client = dogma.client();
125+
126+
final Entry<JsonNode> json = client.getFile(dogma.project(), dogma.repo1(), Revision.HEAD,
127+
Query.ofJson("/test/test1.json5")).join();
128+
assertThatJson(json.content()).isEqualTo(Json5.readTree(JSON5_CONTENTS));
129+
assertThat(json.contentAsText()).isEqualTo(JSON5_CONTENTS);
130+
}
131+
132+
@Test
133+
void jsonPath() {
134+
final CentralDogma client = dogma.client();
135+
136+
final Entry<JsonNode> json1 = client.getFile(
137+
dogma.project(), dogma.repo1(), Revision.HEAD,
138+
Query.ofJsonPath("/test/test1.json5", "$.singleQuotes")).join();
139+
assertThat(json1.content().asText()).isEqualTo("I can use \"double quotes\" here");
140+
141+
final Entry<JsonNode> json2 = client.getFile(
142+
dogma.project(), dogma.repo1(), Revision.HEAD,
143+
Query.ofJsonPath("/test/test1.json5", ImmutableList.of("$.andIn", "$.[0]"))).join();
144+
assertThat(json2.content().asText()).isEqualTo("arrays");
145+
}
146+
}
103147
}

it/src/test/java/com/linecorp/centraldogma/it/MergeFileTest.java

+32-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import java.util.concurrent.CompletionException;
2323

24+
import org.junit.jupiter.api.Nested;
25+
import org.junit.jupiter.api.Test;
2426
import org.junit.jupiter.api.extension.RegisterExtension;
2527
import org.junit.jupiter.params.ParameterizedTest;
2628
import org.junit.jupiter.params.provider.EnumSource;
@@ -50,7 +52,9 @@ protected void scaffold(CentralDogma client) {
5052
client.push("myPro", "myRepo", Revision.HEAD, "Initial files",
5153
Change.ofJsonUpsert("/foo.json", "{ \"a\": \"bar\" }"),
5254
Change.ofJsonUpsert("/foo1.json", "{ \"b\": \"baz\" }"),
53-
Change.ofJsonUpsert("/foo2.json", "{ \"a\": \"new_bar\" }")).join();
55+
Change.ofJsonUpsert("/foo2.json", "{ \"a\": \"new_bar\" }"),
56+
Change.ofJsonUpsert("/foo.json5", "{ a: 'qux' }"),
57+
Change.ofJsonUpsert("/foo1.json5", "{ a: 'new_qux', b: 'quux' }")).join();
5458
}
5559

5660
@Override
@@ -150,4 +154,31 @@ void mergeJsonPaths(ClientType clientType) {
150154
.isInstanceOf(CompletionException.class)
151155
.hasCauseInstanceOf(QueryExecutionException.class);
152156
}
157+
158+
@Nested
159+
class MergeFileJson5Test {
160+
161+
@Test
162+
void mergeJson5Files() {
163+
final MergedEntry<?> merged = dogma.client().mergeFiles(
164+
"myPro", "myRepo", Revision.HEAD,
165+
MergeSource.ofRequired("/foo.json5"),
166+
MergeSource.ofRequired("/foo1.json5")).join();
167+
168+
assertThat(merged.paths()).containsExactly("/foo.json5", "/foo1.json5");
169+
assertThatJson(merged.content()).isEqualTo("{\"a\": \"new_qux\", \"b\": \"quux\"}");
170+
}
171+
172+
@Test
173+
void mergeWithOrdinaryJson() {
174+
final MergedEntry<?> merged = dogma.client().mergeFiles(
175+
"myPro", "myRepo", Revision.HEAD,
176+
MergeSource.ofRequired("/foo.json"),
177+
MergeSource.ofRequired("/foo.json5"),
178+
MergeSource.ofRequired("/foo1.json")).join();
179+
180+
assertThat(merged.paths()).containsExactly("/foo.json", "/foo.json5", "/foo1.json");
181+
assertThatJson(merged.content()).isEqualTo("{\"a\": \"qux\", \"b\": \"baz\"}");
182+
}
183+
}
153184
}

it/src/test/java/com/linecorp/centraldogma/it/WatchTest.java

+39
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616

1717
package com.linecorp.centraldogma.it;
1818

19+
import static java.nio.charset.StandardCharsets.UTF_8;
1920
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
2021
import static org.assertj.core.api.Assertions.assertThat;
2122
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2223
import static org.awaitility.Awaitility.await;
2324

25+
import java.io.File;
26+
import java.io.IOException;
27+
import java.nio.file.Files;
2428
import java.util.Arrays;
2529
import java.util.List;
2630
import java.util.concurrent.CompletableFuture;
31+
import java.util.concurrent.ExecutionException;
2732
import java.util.concurrent.Executors;
2833
import java.util.concurrent.ScheduledExecutorService;
2934
import java.util.concurrent.TimeUnit;
@@ -34,10 +39,13 @@
3439

3540
import org.hamcrest.Matchers;
3641
import org.junit.jupiter.api.AfterAll;
42+
import org.junit.jupiter.api.Nested;
43+
import org.junit.jupiter.api.Test;
3744
import org.junit.jupiter.api.extension.RegisterExtension;
3845
import org.junit.jupiter.params.ParameterizedTest;
3946
import org.junit.jupiter.params.provider.EnumSource;
4047

48+
import com.fasterxml.jackson.core.JsonParseException;
4149
import com.fasterxml.jackson.databind.JsonNode;
4250
import com.fasterxml.jackson.databind.node.TextNode;
4351

@@ -52,6 +60,7 @@
5260
import com.linecorp.centraldogma.common.PushResult;
5361
import com.linecorp.centraldogma.common.Query;
5462
import com.linecorp.centraldogma.common.Revision;
63+
import com.linecorp.centraldogma.internal.Json5;
5564

5665
class WatchTest {
5766

@@ -468,4 +477,34 @@ private static void revertTestFiles(ClientType clientType) {
468477
"Revert test files", changes).join();
469478
}
470479
}
480+
481+
@Nested
482+
class WatchJson5Test {
483+
484+
@Test
485+
void watchJson5() throws Exception {
486+
final CentralDogma client = dogma.client();
487+
488+
final CompletableFuture<Entry<JsonNode>> future = client.watchFile(
489+
dogma.project(), dogma.repo1(), Revision.HEAD, Query.ofJson("/test/test1.json5"));
490+
491+
assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS))
492+
.isInstanceOf(TimeoutException.class);
493+
494+
// Make change to an irrelevant file.
495+
client.push(dogma.project(), dogma.repo1(), Revision.HEAD, "Add foo.json",
496+
Change.ofJsonUpsert("/test/foo.json", "{}")).join();
497+
498+
assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS))
499+
.isInstanceOf(TimeoutException.class);
500+
501+
// Make change to a relevant file.
502+
final PushResult result = client.push(
503+
dogma.project(), dogma.repo1(), Revision.HEAD, "Edit test1.json5",
504+
Change.ofJsonUpsert("/test/test1.json5", "{a: 'foo'}")).join();
505+
506+
assertThat(future.get(3, TimeUnit.SECONDS)).isEqualTo(
507+
Entry.ofJson(result.revision(), "/test/test1.json5", "{a: 'foo'}\n"));
508+
}
509+
}
471510
}

0 commit comments

Comments
 (0)