Skip to content

Commit e5df1e6

Browse files
committed
test: test for heartbeat
1 parent c9ea9d1 commit e5df1e6

File tree

7 files changed

+55
-10
lines changed

7 files changed

+55
-10
lines changed

plugin-api-test-client/.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-api-test-client/.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-api-test-client/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-api-test-client/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repositories {
1414
dependencies {
1515
implementation("org.springframework.boot:spring-boot-starter-web:3.4.2")
1616
implementation("com.fasterxml.jackson.core:jackson-databind:2.18.2")
17-
implementation("com.vaadin:vaadin-core:24.6.5")
17+
implementation("com.vaadin:vaadin-core:24.7.4")
1818
testImplementation("org.springframework.boot:spring-boot-starter-test:3.4.2")
1919
}
2020

plugin-api-test-client/src/main/java/com/vaadin/plugin/Client.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ public RestClient.ResponseSpec delete(Path path) throws IOException {
5252
return send("delete", new Message.DeleteMessage(path.toString()));
5353
}
5454

55+
public RestClient.ResponseSpec heartbeat() throws IOException {
56+
return send("heartbeat", new Message.HeartbeatMessage());
57+
}
58+
5559
private RestClient.ResponseSpec send(String command, Object data) throws JsonProcessingException {
5660
Message.CopilotRestRequest message = new Message.CopilotRestRequest(command, projectBasePath, data);
5761
String body = new ObjectMapper().writeValueAsString(message);
58-
org.springframework.web.client.RestClient.ResponseSpec response = org.springframework.web.client.RestClient.create().post()
62+
return org.springframework.web.client.RestClient.create().post()
5963
.uri(endpoint).contentType(MediaType.APPLICATION_JSON)
6064
.body(body).retrieve();
61-
return response;
6265
}
6366

6467
}

plugin-api-test-client/src/main/java/com/vaadin/plugin/Message.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.vaadin.plugin;
22

33
import java.util.List;
4+
import java.util.Set;
45

56
public class Message {
67

@@ -31,4 +32,10 @@ record CompileMessage(List<String> files) {
3132
record DeleteMessage(String file) {
3233
}
3334

35+
record HeartbeatMessage() {
36+
}
37+
38+
record HeartbeatResponse(Boolean hasCompilationError, Set<String> filesContainCompilationError) {
39+
}
40+
3441
}

plugin-api-test-client/src/test/java/com/vaadin/plugin/PluginApiTests.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
import java.nio.file.Files;
1515
import java.nio.file.Path;
1616
import java.nio.file.attribute.FileAttribute;
17-
import java.util.Base64;
18-
import java.util.Map;
19-
import java.util.Properties;
20-
import java.util.UUID;
17+
import java.util.*;
2118
import java.util.function.Predicate;
2219

2320
@SpringBootTest(classes = {SpringBootApplication.class})
@@ -33,6 +30,12 @@ protected Path getTestResourcePath(String childPath) {
3330
.resolve(childPath);
3431
}
3532

33+
protected Path getSourcePath(String childPath) {
34+
return Path.of(projectBasePath)
35+
.resolve("src/main/java")
36+
.resolve(childPath);
37+
}
38+
3639
@BeforeAll
3740
public static void beforeAll() throws IOException {
3841
projectBasePath = Path.of(System.getProperty("user.dir")).toString();
@@ -121,6 +124,38 @@ public void testUndoRedo() throws IOException, InterruptedException {
121124
Assertions.assertFalse(performed);
122125
}
123126

127+
// Run using Debug to trigger compile on save
128+
@Test
129+
public void testHeartbeat() throws IOException, InterruptedException {
130+
var response = client.heartbeat();
131+
var body = response.body(Message.HeartbeatResponse.class);
132+
Assertions.assertFalse(body.hasCompilationError());
133+
Assertions.assertEquals(Collections.EMPTY_SET, body.filesContainCompilationError());
134+
135+
var filePath = getSourcePath("com/vaadin/plugin/Test.java");
136+
filePath.toFile().deleteOnExit();
137+
138+
response = client.write(filePath, "package com.vaadin.plugin;\n" +
139+
"\n" +
140+
"public class Test {\n" +
141+
"asdasdasd" +
142+
"}");
143+
assertHttpOk(response);
144+
Thread.sleep(2000);
145+
146+
for (int i = 0 ; i < 10 ; ++i) {
147+
response = client.heartbeat();
148+
body = response.body(Message.HeartbeatResponse.class);
149+
if (body.hasCompilationError()) {
150+
Assertions.assertEquals(Collections.EMPTY_SET, body.filesContainCompilationError());
151+
return;
152+
}
153+
Thread.sleep(2000);
154+
}
155+
156+
Assertions.fail("No compilation error received");
157+
}
158+
124159
// add more tests when needed
125160

126161
private void assertNewFileCreated(Path file) {

0 commit comments

Comments
 (0)