+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
![Generated image]()
+
+
+
+
+
+
+
diff --git a/spring-ai/src/test/java/com/example/springai/SpringAiApplicationTests.java b/spring-ai/src/test/java/com/example/springai/SpringAiApplicationTests.java
new file mode 100644
index 000000000..a7d8f14d8
--- /dev/null
+++ b/spring-ai/src/test/java/com/example/springai/SpringAiApplicationTests.java
@@ -0,0 +1,17 @@
+package com.example.springai;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+
+@SpringBootTest
+@TestPropertySource(
+ properties = {
+ "spring.ai.openai.api-key=test-key",
+ "spring.ai.openai.chat.options.model=gpt-4o-mini"
+ })
+class SpringAiApplicationTests {
+
+ @Test
+ void contextLoads() {}
+}
diff --git a/spring-ai/src/test/java/com/example/springai/controller/ChatControllerTest.java b/spring-ai/src/test/java/com/example/springai/controller/ChatControllerTest.java
new file mode 100644
index 000000000..2507ffe93
--- /dev/null
+++ b/spring-ai/src/test/java/com/example/springai/controller/ChatControllerTest.java
@@ -0,0 +1,99 @@
+package com.example.springai.controller;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import com.example.springai.model.ChatResponse;
+import com.example.springai.service.ChatService;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.test.context.bean.override.mockito.MockitoBean;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+
+@WebMvcTest(ChatController.class)
+class ChatControllerTest {
+
+ @Autowired private MockMvc mockMvc;
+
+ @MockitoBean private ChatService chatService;
+
+ @Test
+ void chatGet_shouldReturnResponse() throws Exception {
+ when(chatService.chat("Hello")).thenReturn(new ChatResponse("Hi there!", "gpt-4o-mini"));
+
+ mockMvc.perform(get("/api/chat").param("message", "Hello"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.response").value("Hi there!"))
+ .andExpect(jsonPath("$.model").value("gpt-4o-mini"));
+ }
+
+ @Test
+ void chatPost_shouldReturnResponse() throws Exception {
+ when(chatService.chatWithOptions(eq("Hello"), any(), any()))
+ .thenReturn(new ChatResponse("Hi there!", "gpt-4o-mini"));
+
+ mockMvc.perform(
+ post("/api/chat")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"message\": \"Hello\"}"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.response").value("Hi there!"));
+ }
+
+ @Test
+ void chatPost_withBlankMessage_shouldReturnBadRequest() throws Exception {
+ mockMvc.perform(
+ post("/api/chat")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"message\": \"\"}"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void summarize_shouldReturnSummary() throws Exception {
+ when(chatService.summarize(any()))
+ .thenReturn(new ChatResponse("Short summary.", "gpt-4o-mini"));
+
+ mockMvc.perform(
+ post("/api/chat/summarize")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"text\": \"Long text to summarize\"}"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.response").value("Short summary."));
+ }
+
+ @Test
+ void translate_shouldReturnTranslation() throws Exception {
+ when(chatService.translate(any(), eq("Spanish")))
+ .thenReturn(new ChatResponse("Hola", "gpt-4o-mini"));
+
+ mockMvc.perform(
+ post("/api/chat/translate")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(
+ "{\"text\": \"Hello\", \"targetLanguage\":"
+ + " \"Spanish\"}"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.response").value("Hola"));
+ }
+
+ @Test
+ void analyzeCode_shouldReturnAnalysis() throws Exception {
+ when(chatService.analyzeCode(any()))
+ .thenReturn(new ChatResponse("This is a simple function.", "gpt-4o-mini"));
+
+ mockMvc.perform(
+ post("/api/chat/analyze-code")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"code\": \"int x = 1;\"}"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.response").value("This is a simple function."));
+ }
+}
diff --git a/spring-ai/src/test/java/com/example/springai/controller/ImageControllerTest.java b/spring-ai/src/test/java/com/example/springai/controller/ImageControllerTest.java
new file mode 100644
index 000000000..1d13d1959
--- /dev/null
+++ b/spring-ai/src/test/java/com/example/springai/controller/ImageControllerTest.java
@@ -0,0 +1,46 @@
+package com.example.springai.controller;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import com.example.springai.model.ImageResponse;
+import com.example.springai.service.ImageService;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.test.context.bean.override.mockito.MockitoBean;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+
+@WebMvcTest(ImageController.class)
+class ImageControllerTest {
+
+ @Autowired private MockMvc mockMvc;
+
+ @MockitoBean private ImageService imageService;
+
+ @Test
+ void generateImage_shouldReturnImageUrl() throws Exception {
+ when(imageService.generateImage(any(), any(), any()))
+ .thenReturn(new ImageResponse("https://example.com/image.png", "A cat"));
+
+ mockMvc.perform(
+ post("/api/image/generate")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"prompt\": \"A cute cat\"}"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.url").value("https://example.com/image.png"));
+ }
+
+ @Test
+ void generateImage_withBlankPrompt_shouldReturnBadRequest() throws Exception {
+ mockMvc.perform(
+ post("/api/image/generate")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"prompt\": \"\"}"))
+ .andExpect(status().isBadRequest());
+ }
+}