Skip to content

Commit f90788f

Browse files
committed
WIP: start on tests
This commit will be reset and updated later, but I'm committing it so I don't lose work
1 parent bb255ee commit f90788f

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

e2e-tests/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dependencies {
6868
testImplementation "com.zaxxer:HikariCP:5.1.0"
6969
testImplementation("org.postgresql:postgresql:42.6.0")
7070

71-
testImplementation 'com.microsoft.playwright:playwright:1.37.0'
71+
testImplementation 'com.microsoft.playwright:playwright:1.55.0'
7272

7373
testImplementation 'org.glassfish:javax.json:1.1.4'
7474
testImplementation 'org.apache.commons:commons-lang3:3.13.0'

e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/BindingsTests.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.io.IOException;
3838
import java.io.StringReader;
3939
import java.nio.charset.StandardCharsets;
40+
import java.nio.file.Path;
4041
import java.util.List;
4142
import java.util.Map;
4243
import java.util.Optional;
@@ -1484,7 +1485,7 @@ void nonEmptyWorkspaceWithDepth() {
14841485
}
14851486

14861487
/**
1487-
* Tests for the /ws/{workspaceId}/<filePath> routes.
1488+
* Tests for the /ws/{workspaceId}/<path> routes.
14881489
*
14891490
* Disabled because the suite is skeletoned but not implemented.
14901491
*/
@@ -1898,6 +1899,39 @@ void conflictedIfDestinationExists() {
18981899
}
18991900
}
19001901

1902+
/**
1903+
* Tests for the /ws/bulk/{workspaceId}/ routes.
1904+
*
1905+
* Disabled because the suite is skeletoned but not implemented.
1906+
*/
1907+
@Nested
1908+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1909+
class BulkWSRoutes {
1910+
private int workspaceId;
1911+
1912+
@BeforeAll
1913+
void beforeAll() throws IOException {
1914+
workspaceId = wsServer.createWorkspace("bulkRoutesWS", parcelId);
1915+
}
1916+
1917+
@AfterAll
1918+
void afterAll() throws IOException {
1919+
wsServer.deleteWorkspace(workspaceId);
1920+
}
1921+
1922+
@Test
1923+
void basicTest() {
1924+
final var resp = wsServer.bulkPutFile(
1925+
ownerToken,
1926+
workspaceId,
1927+
List.of(Path.of("myFile.txt")),
1928+
List.of("this is my file contents"));
1929+
1930+
assertEquals(207, resp.status());
1931+
}
1932+
1933+
}
1934+
19011935
/**
19021936
* Tests for the response of the `authorize` before on `/ws/*` routes.
19031937
* Uses GET /ws/{workspaceId} for testing

e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/WorkspaceRequests.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.io.IOException;
1313
import java.nio.charset.StandardCharsets;
1414
import java.nio.file.Path;
15+
import java.util.List;
1516
import java.util.Map;
1617
import java.util.Optional;
1718

@@ -23,7 +24,8 @@ public enum RequestType {GET, PUT, POST, DELETE}
2324

2425
public WorkspaceRequests(Playwright playwright){
2526
request = playwright.request().newContext(new APIRequest.NewContextOptions()
26-
.setBaseURL(BaseURL.WORKSPACE_SERVER.url));
27+
.setBaseURL(BaseURL.WORKSPACE_SERVER.url)
28+
.setTimeout(0)); // Temp disable timeout while debugging
2729
}
2830

2931
/**
@@ -191,6 +193,39 @@ public APIResponse deleteWorkspace(String authToken, int workspaceId) {
191193
}
192194

193195

196+
/**
197+
* Call the 'put file' endpoint in the Workspace server. Does not pass the "overwrite" flag.
198+
* @param token The JWT token for the user making the request
199+
* @param workspaceId The workspace to insert the file into
200+
* @param fileLocation Where to place the plan
201+
* @param fileContents The contents of the file to be inserted
202+
* @return The APIResponse from the server
203+
*/
204+
public APIResponse bulkPutFile(String token, int workspaceId, List<Path> fileLocation, List<String> fileContents) {
205+
final var formData = FormData.create();
206+
final var bodyArray = Json.createArrayBuilder();
207+
208+
for(int i = 0; i < fileLocation.size(); ++i) {
209+
final var obj = Json.createObjectBuilder()
210+
.add("path", fileLocation.get(i).toString())
211+
.add("type", "file");
212+
final var filePayload = new FilePayload(
213+
fileLocation.get(i).toString(),
214+
"text/plain",
215+
fileContents.get(i).getBytes(StandardCharsets.UTF_8));
216+
217+
bodyArray.add(obj);
218+
formData.append("files", filePayload);
219+
}
220+
221+
final var options = RequestOptions
222+
.create()
223+
.setHeader("Authorization", "Bearer "+token)
224+
.setMultipart(formData.set("body", bodyArray.build().toString()));
225+
226+
return request.put("/ws/bulk/%d".formatted(workspaceId), options);
227+
}
228+
194229
@Override
195230
public void close() {
196231
request.dispose();

0 commit comments

Comments
 (0)