feat: restore missing Import Model List button and add REST bridge for ComfyUI integration
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package de.tki.comfymodels.service;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class InstallationPathTest {
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test
|
||||
void testStandardLayout() throws IOException {
|
||||
Path customNodes = tempDir.resolve("custom_nodes");
|
||||
Files.createDirectory(customNodes);
|
||||
|
||||
File inputPath = tempDir.toFile();
|
||||
File customNodesDir = findCustomNodes(inputPath);
|
||||
|
||||
assertNotNull(customNodesDir);
|
||||
assertEquals(customNodes.toAbsolutePath().toString(), customNodesDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPortableLayout() throws IOException {
|
||||
Path comfyDir = tempDir.resolve("ComfyUI");
|
||||
Files.createDirectory(comfyDir);
|
||||
Path customNodes = comfyDir.resolve("custom_nodes");
|
||||
Files.createDirectory(customNodes);
|
||||
|
||||
File inputPath = tempDir.toFile();
|
||||
File customNodesDir = findCustomNodes(inputPath);
|
||||
|
||||
assertNotNull(customNodesDir);
|
||||
assertEquals(customNodes.toAbsolutePath().toString(), customNodesDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDesktopAppLayout() throws IOException {
|
||||
Path resources = tempDir.resolve("resources");
|
||||
Files.createDirectory(resources);
|
||||
Path comfyDir = resources.resolve("ComfyUI");
|
||||
Files.createDirectory(comfyDir);
|
||||
Path customNodes = comfyDir.resolve("custom_nodes");
|
||||
Files.createDirectory(customNodes);
|
||||
|
||||
File inputPath = tempDir.toFile();
|
||||
File customNodesDir = findCustomNodes(inputPath);
|
||||
|
||||
assertNotNull(customNodesDir);
|
||||
assertEquals(customNodes.toAbsolutePath().toString(), customNodesDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDirectSelection() throws IOException {
|
||||
Path customNodes = tempDir.resolve("custom_nodes");
|
||||
Files.createDirectory(customNodes);
|
||||
|
||||
File inputPath = customNodes.toFile();
|
||||
File customNodesDir = findCustomNodes(inputPath);
|
||||
|
||||
assertNotNull(customNodesDir);
|
||||
assertEquals(customNodes.toAbsolutePath().toString(), customNodesDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic extracted from Main.java for testing
|
||||
*/
|
||||
private File findCustomNodes(File inputPath) {
|
||||
File c1 = new File(inputPath, "custom_nodes");
|
||||
File c2 = new File(inputPath, "ComfyUI" + File.separator + "custom_nodes");
|
||||
File c3 = new File(inputPath, "resources" + File.separator + "ComfyUI" + File.separator + "custom_nodes");
|
||||
File c4 = inputPath;
|
||||
|
||||
if (c1.exists() && c1.isDirectory()) return c1;
|
||||
if (c2.exists() && c2.isDirectory()) return c2;
|
||||
if (c3.exists() && c3.isDirectory()) return c3;
|
||||
if (c4.getName().equalsIgnoreCase("custom_nodes") && c4.isDirectory()) return c4;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package de.tki.comfymodels.service;
|
||||
|
||||
import de.tki.comfymodels.service.impl.RestBridgeService;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class RestBridgeServiceTest {
|
||||
|
||||
private RestBridgeService restBridge;
|
||||
private final int testPort = 12346;
|
||||
private final String testToken = "test-token";
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
restBridge = new RestBridgeService();
|
||||
restBridge.setPort(testPort);
|
||||
restBridge.setApiToken(testToken);
|
||||
restBridge.startServer();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
restBridge.stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWorkflowImport() throws Exception {
|
||||
AtomicReference<String> receivedWorkflow = new AtomicReference<>();
|
||||
restBridge.setWorkflowConsumer(receivedWorkflow::set);
|
||||
|
||||
String testJson = "{\"nodes\": []}";
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://127.0.0.1:" + testPort + "/import"))
|
||||
.header("Authorization", "Bearer " + testToken)
|
||||
.POST(HttpRequest.BodyPublishers.ofString(testJson))
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
assertEquals(200, response.statusCode());
|
||||
assertEquals(testJson, receivedWorkflow.get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user