From 67d3c518d05cc8b33b6123d17d04b629b0f72f07 Mon Sep 17 00:00:00 2001 From: Robothy Date: Wed, 11 Oct 2023 16:51:27 +0800 Subject: [PATCH] add ut --- build.gradle | 10 +++++++ .../github/robothy/sdwebui/sdk/Txt2Image.java | 9 +++++++ .../sdwebui/sdk/models/SystemInfoTest.java | 22 ++++++++++++++++ .../sdk/models/results/Txt2ImgResultTest.java | 26 +++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 src/test/java/io/github/robothy/sdwebui/sdk/models/SystemInfoTest.java create mode 100644 src/test/java/io/github/robothy/sdwebui/sdk/models/results/Txt2ImgResultTest.java diff --git a/build.gradle b/build.gradle index cd00c7d..f9faa5d 100644 --- a/build.gradle +++ b/build.gradle @@ -47,6 +47,16 @@ dependencies { java { withSourcesJar() withJavadocJar() + sourceCompatibility(JavaVersion.VERSION_1_8) + targetCompatibility(JavaVersion.VERSION_1_8) +} + +tasks.compileJava { + options.encoding = "UTF-8" +} + +tasks.compileTestJava { + options.encoding = "UTF-8" } test { diff --git a/src/main/java/io/github/robothy/sdwebui/sdk/Txt2Image.java b/src/main/java/io/github/robothy/sdwebui/sdk/Txt2Image.java index a655bbf..0f925b8 100644 --- a/src/main/java/io/github/robothy/sdwebui/sdk/Txt2Image.java +++ b/src/main/java/io/github/robothy/sdwebui/sdk/Txt2Image.java @@ -5,6 +5,15 @@ public interface Txt2Image { + /** + * Generate images from text. + * + * @param options The options to generate images. + * @return The result of the generation. + * + * @throws io.github.robothy.sdwebui.sdk.exceptions.SdWebuiServerValidationException + * @throws io.github.robothy.sdwebui.sdk.exceptions.SdWebuiBadRequestException + */ Txt2ImgResult txt2Img(Txt2ImageOptions options); } diff --git a/src/test/java/io/github/robothy/sdwebui/sdk/models/SystemInfoTest.java b/src/test/java/io/github/robothy/sdwebui/sdk/models/SystemInfoTest.java new file mode 100644 index 0000000..9e2d604 --- /dev/null +++ b/src/test/java/io/github/robothy/sdwebui/sdk/models/SystemInfoTest.java @@ -0,0 +1,22 @@ +package io.github.robothy.sdwebui.sdk.models; + +import static org.junit.jupiter.api.Assertions.*; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +class SystemInfoTest { + + @Test + void testSerialization() throws JsonProcessingException { + SystemInfo systemInfo = new SystemInfo(); + systemInfo.setEndpoint("http://localhost:8080"); + systemInfo.setPlatform("Linux"); + systemInfo.setPythonVersion("3.8.5"); + systemInfo.setSdwebuiVersion("0.0.1"); + ObjectMapper objectMapper = new ObjectMapper(); + assertEquals(systemInfo, objectMapper + .readValue(objectMapper.writeValueAsString(systemInfo), SystemInfo.class)); + } + +} \ No newline at end of file diff --git a/src/test/java/io/github/robothy/sdwebui/sdk/models/results/Txt2ImgResultTest.java b/src/test/java/io/github/robothy/sdwebui/sdk/models/results/Txt2ImgResultTest.java new file mode 100644 index 0000000..fb38456 --- /dev/null +++ b/src/test/java/io/github/robothy/sdwebui/sdk/models/results/Txt2ImgResultTest.java @@ -0,0 +1,26 @@ +package io.github.robothy.sdwebui.sdk.models.results; + +import static org.junit.jupiter.api.Assertions.*; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.robothy.sdwebui.sdk.models.options.Txt2ImageOptions; +import java.util.List; +import org.junit.jupiter.api.Test; + +class Txt2ImgResultTest { + + @Test + void testSerialization() throws JsonProcessingException { + Txt2ImgResult txt2ImgResult = new Txt2ImgResult(); + txt2ImgResult.setImages(List.of("image1", "image2")); + txt2ImgResult.setInfo("info"); + txt2ImgResult.setParameters(Txt2ImageOptions.builder() + .prompt("1dog") + .build()); + + ObjectMapper objectMapper = new ObjectMapper(); + assertEquals(txt2ImgResult, objectMapper.readValue(objectMapper + .writeValueAsString(txt2ImgResult), Txt2ImgResult.class)); + } + +} \ No newline at end of file