Skip to content

Commit d5ec497

Browse files
authored
Merge branch 'main' into mcp-pom-version
2 parents 91bef92 + b34feaa commit d5ec497

File tree

3 files changed

+180
-0
lines changed

3 files changed

+180
-0
lines changed

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"redhat.java",
4+
"vscjava.vscode-java-pack",
5+
"josevseb.google-java-format-for-vs-code"
6+
]
7+
}

.vscode/settings.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
// formatOnType and formatOnPaste is a very bad idea for slow formatters
3+
// (such as an external Google Java Format invocation exec), so just on Save:
4+
"editor.formatOnSave": true,
5+
"editor.formatOnType": false,
6+
"editor.formatOnPaste": false,
7+
8+
"files.insertFinalNewline": true,
9+
"files.trimTrailingWhitespace": true,
10+
11+
"[java]": {
12+
"editor.tabSize": 2,
13+
// Format Java using https://github.com/google/google-java-format,
14+
// via https://github.com/JoseVSeb/google-java-format-for-vs-code
15+
"editor.defaultFormatter": "josevseb.google-java-format-for-vs-code",
16+
"editor.codeActionsOnSave": {
17+
// Used by at least JS as well as Java, so only overridden for [java]
18+
"source.organizeImports": "always",
19+
"source.addMissingImports": "never"
20+
}
21+
},
22+
// Keep this version in sync with the same version in pom.xml
23+
// NB: Changes to this are only taken into account on start-up, so need to restart.
24+
"java.format.settings.google.version": "1.27.0",
25+
// TODO https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/3050
26+
"java.compile.nullAnalysis.mode": "automatic",
27+
"java.completion.importOrder": ["#", "", "javax", "java"], //# is static
28+
"java.completion.favoriteStaticMembers": ["com.google.common.truth.Truth.*"],
29+
"java.configuration.updateBuildConfiguration": "automatic",
30+
"java.import.maven.enabled": true
31+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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.web;
18+
19+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
20+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
21+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
22+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
23+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
24+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
25+
26+
import org.hamcrest.Matchers;
27+
import org.junit.jupiter.api.Test;
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
30+
import org.springframework.boot.test.context.SpringBootTest;
31+
import org.springframework.http.MediaType;
32+
import org.springframework.test.web.servlet.MockMvc;
33+
34+
/**
35+
* Integration tests for the {@link AdkWebServer}.
36+
*
37+
* <p>These tests use MockMvc to simulate HTTP requests and then verify the expected responses from
38+
* the ADK API server.
39+
*
40+
* @author <a href="http://www.vorburger.ch">Michael Vorburger.ch</a>, with Google Gemini Code
41+
* Assist in Agent mode
42+
*/
43+
@SpringBootTest
44+
@AutoConfigureMockMvc
45+
public class AdkWebServerTest {
46+
47+
@Autowired private MockMvc mockMvc;
48+
49+
@Test
50+
public void listApps_shouldReturnOkAndEmptyList() throws Exception {
51+
mockMvc.perform(get("/list-apps")).andExpect(status().isOk()).andExpect(content().json("[]"));
52+
}
53+
54+
@Test
55+
public void createSession_shouldReturnCreated() throws Exception {
56+
var result =
57+
mockMvc
58+
.perform(
59+
post("/apps/test-app/users/test-user/sessions")
60+
.contentType(MediaType.APPLICATION_JSON)
61+
.content("{}"))
62+
.andExpect(status().isOk())
63+
.andExpect(jsonPath("$.appName", Matchers.is("test-app")))
64+
.andExpect(jsonPath("$.userId", Matchers.is("test-user")))
65+
.andReturn();
66+
67+
var responseBody = result.getResponse().getContentAsString();
68+
var sessionId = com.jayway.jsonpath.JsonPath.read(responseBody, "$.id");
69+
mockMvc.perform(delete("/apps/test-app/users/test-user/sessions/" + sessionId));
70+
}
71+
72+
@Test
73+
public void createSessionWithId_shouldReturnCreated() throws Exception {
74+
try {
75+
mockMvc
76+
.perform(
77+
post("/apps/test-app/users/test-user/sessions/test-session")
78+
.contentType(MediaType.APPLICATION_JSON)
79+
.content("{}"))
80+
.andExpect(status().isOk())
81+
.andExpect(jsonPath("$.appName", Matchers.is("test-app")))
82+
.andExpect(jsonPath("$.userId", Matchers.is("test-user")))
83+
.andExpect(jsonPath("$.id", Matchers.is("test-session")));
84+
} finally {
85+
mockMvc.perform(delete("/apps/test-app/users/test-user/sessions/test-session"));
86+
}
87+
}
88+
89+
@Test
90+
public void deleteSession_shouldReturnNoContent() throws Exception {
91+
mockMvc.perform(
92+
post("/apps/test-app/users/test-user/sessions/test-session-to-delete")
93+
.contentType(MediaType.APPLICATION_JSON)
94+
.content("{}"));
95+
96+
mockMvc
97+
.perform(delete("/apps/test-app/users/test-user/sessions/test-session-to-delete"))
98+
.andExpect(status().isNoContent());
99+
}
100+
101+
@Test
102+
public void getSession_shouldReturnOk() throws Exception {
103+
mockMvc.perform(
104+
post("/apps/test-app/users/test-user/sessions/test-session")
105+
.contentType(MediaType.APPLICATION_JSON)
106+
.content("{}"));
107+
108+
try {
109+
mockMvc
110+
.perform(get("/apps/test-app/users/test-user/sessions/test-session"))
111+
.andExpect(status().isOk())
112+
.andExpect(jsonPath("$.appName", Matchers.is("test-app")))
113+
.andExpect(jsonPath("$.userId", Matchers.is("test-user")))
114+
.andExpect(jsonPath("$.id", Matchers.is("test-session")));
115+
} finally {
116+
mockMvc.perform(delete("/apps/test-app/users/test-user/sessions/test-session"));
117+
}
118+
}
119+
120+
@Test
121+
public void listSessions_shouldReturnOk() throws Exception {
122+
mockMvc.perform(
123+
post("/apps/test-app/users/test-user/sessions/test-session-1")
124+
.contentType(MediaType.APPLICATION_JSON)
125+
.content("{}"));
126+
mockMvc.perform(
127+
post("/apps/test-app/users/test-user/sessions/test-session-2")
128+
.contentType(MediaType.APPLICATION_JSON)
129+
.content("{}"));
130+
131+
mockMvc
132+
.perform(get("/apps/test-app/users/test-user/sessions"))
133+
.andExpect(status().isOk())
134+
.andExpect(
135+
jsonPath(
136+
"$[?(@.id == 'test-session-1' || @.id == 'test-session-2')].id",
137+
Matchers.containsInAnyOrder("test-session-1", "test-session-2")));
138+
139+
mockMvc.perform(delete("/apps/test-app/users/test-user/sessions/test-session-1"));
140+
mockMvc.perform(delete("/apps/test-app/users/test-user/sessions/test-session-2"));
141+
}
142+
}

0 commit comments

Comments
 (0)