|
| 1 | +/* |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.adk.starters.springboot; |
| 18 | + |
| 19 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 20 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 21 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
| 22 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 23 | + |
| 24 | +import com.google.adk.agents.BaseAgent; |
| 25 | +import com.google.adk.agents.LlmAgent; |
| 26 | +import com.google.adk.web.AgentStaticLoader; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | +import org.springframework.beans.factory.annotation.Autowired; |
| 29 | +import org.springframework.boot.SpringApplication; |
| 30 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 31 | +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
| 32 | +import org.springframework.boot.test.context.SpringBootTest; |
| 33 | +import org.springframework.context.annotation.Bean; |
| 34 | +import org.springframework.context.annotation.Configuration; |
| 35 | +import org.springframework.test.web.servlet.MockMvc; |
| 36 | + |
| 37 | +/** |
| 38 | + * Integration tests for the ADK Spring Boot Starter. |
| 39 | + * |
| 40 | + * <p>These tests use MockMvc to simulate HTTP requests and verify the expected responses from the |
| 41 | + * ADK API server, ensuring that the Spring Boot autoconfiguration works correctly. |
| 42 | + */ |
| 43 | +@SpringBootTest(properties = "adk.agents.loader=static") |
| 44 | +@AutoConfigureMockMvc |
| 45 | +public class AdkSpringbootStarterTest { |
| 46 | + |
| 47 | + @Autowired private AgentStaticLoader agentStaticLoader; |
| 48 | + |
| 49 | + @Autowired private MockMvc mockMvc; |
| 50 | + |
| 51 | + @Test |
| 52 | + void testAgentStaticLoaderIsLoaded() throws Exception { |
| 53 | + assertNotNull(agentStaticLoader); |
| 54 | + mockMvc |
| 55 | + .perform(get("/list-apps")) |
| 56 | + .andExpect(status().isOk()) |
| 57 | + .andExpect(content().json("[\"test_agent\"]")); |
| 58 | + } |
| 59 | + |
| 60 | + @SpringBootApplication |
| 61 | + public static class TestApplication { |
| 62 | + public static void main(String[] args) { |
| 63 | + SpringApplication.run(TestApplication.class, args); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Configuration |
| 68 | + public static class AppConfig { |
| 69 | + @Bean("agentLoader") |
| 70 | + public AgentStaticLoader agentStaticLoader() { |
| 71 | + BaseAgent testAgent = |
| 72 | + LlmAgent.builder() |
| 73 | + .name("test_agent") |
| 74 | + .model("gemini-2.0-flash-lite") |
| 75 | + .description("Test agent for demonstrating AgentStaticLoader") |
| 76 | + .instruction("You are a test agent.") |
| 77 | + .build(); |
| 78 | + return new AgentStaticLoader(testAgent); |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments