From f2697cbd0a672a8f8f6ee15e0fcaaf5215d11e86 Mon Sep 17 00:00:00 2001 From: Ayush Agrawal Date: Mon, 27 Jul 2026 11:00:00 -0700 Subject: [PATCH] chore: internal PiperOrigin-RevId: 954720709 --- .../java/com/google/genai/MultistepTest.java | 84 ++++++------------- 1 file changed, 25 insertions(+), 59 deletions(-) diff --git a/src/test/java/com/google/genai/MultistepTest.java b/src/test/java/com/google/genai/MultistepTest.java index 41888f19b40..24402db936f 100644 --- a/src/test/java/com/google/genai/MultistepTest.java +++ b/src/test/java/com/google/genai/MultistepTest.java @@ -159,32 +159,18 @@ private static Object createGetDelete(Client client, Map paramet if (client.vertexAI()) { cache = client.caches.create(model, config); } else { - String filePath = "tests/data/google.png"; - boolean createdFile = false; - try { - // Temp test artifact creation. - if (!Files.exists(Paths.get(filePath))) { - Files.createDirectories(Paths.get(filePath).getParent()); - Files.write(Paths.get(filePath), "fake content".getBytes()); - createdFile = true; - } + String filePath = "src/test/resources/google.png"; - File file = client.files.upload(filePath, null); - List parts = new ArrayList<>(); - for (int i = 0; i < 5; i++) { - parts.add(Part.fromUri(file.uri().get(), file.mimeType().get())); - } - CreateCachedContentConfig mldevConfig = - CreateCachedContentConfig.builder() - .contents(Collections.singletonList(Content.fromParts(parts.toArray(new Part[0])))) - .build(); - cache = client.caches.create(model, mldevConfig); - } finally { - // Temp test artifact cleanup. - if (createdFile) { - Files.deleteIfExists(Paths.get(filePath)); - } + File file = client.files.upload(filePath, null); + List parts = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + parts.add(Part.fromUri(file.uri().get(), file.mimeType().get())); } + CreateCachedContentConfig mldevConfig = + CreateCachedContentConfig.builder() + .contents(Collections.singletonList(Content.fromParts(parts.toArray(new Part[0])))) + .build(); + cache = client.caches.create(model, mldevConfig); } CachedContent gotCache = client.caches.get(cache.name().get(), null); return client.caches.delete(gotCache.name().get(), null); @@ -203,32 +189,18 @@ private static Object createUpdateGet(Client client, Map paramet if (client.vertexAI()) { cache = client.caches.create(model, config); } else { - String filePath = "tests/data/google.png"; - boolean createdFile = false; - try { - // Temp test artifact creation. - if (!Files.exists(Paths.get(filePath))) { - Files.createDirectories(Paths.get(filePath).getParent()); - Files.write(Paths.get(filePath), "fake content".getBytes()); - createdFile = true; - } + String filePath = "src/test/resources/google.png"; - File file = client.files.upload(filePath, null); - List parts = new ArrayList<>(); - for (int i = 0; i < 5; i++) { - parts.add(Part.fromUri(file.uri().get(), file.mimeType().get())); - } - CreateCachedContentConfig mldevConfig = - CreateCachedContentConfig.builder() - .contents(Collections.singletonList(Content.fromParts(parts.toArray(new Part[0])))) - .build(); - cache = client.caches.create(model, mldevConfig); - } finally { - // Temp test artifact cleanup. - if (createdFile) { - Files.deleteIfExists(Paths.get(filePath)); - } + File file = client.files.upload(filePath, null); + List parts = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + parts.add(Part.fromUri(file.uri().get(), file.mimeType().get())); } + CreateCachedContentConfig mldevConfig = + CreateCachedContentConfig.builder() + .contents(Collections.singletonList(Content.fromParts(parts.toArray(new Part[0])))) + .build(); + cache = client.caches.create(model, mldevConfig); } CachedContent updatedCache = client.caches.update( @@ -262,6 +234,9 @@ private static Object sendMessageStream(Client client, Map param private static Object uploadGetDelete(Client client, Map parameters) throws Exception { String filePath = (String) parameters.get("filePath"); + if (filePath != null && filePath.contains("google.png")) { + filePath = "src/test/resources/google.png"; + } boolean createdFile = false; try { // Temp test artifact creation. @@ -276,7 +251,7 @@ private static Object uploadGetDelete(Client client, Map paramet return client.files.delete(gotFile.name().get(), null); } finally { // Temp test artifact cleanup. - if (createdFile && filePath.endsWith("google.png")) { + if (createdFile) { Files.deleteIfExists(Paths.get(filePath)); } } @@ -347,16 +322,7 @@ private static Object multimodalSearchFlow(Client client, Map pa .build()); // Upload Image - // Resolve path relative to google3 - String google3Path = ""; - String currentDir = System.getProperty("user.dir"); - int lastIndex = currentDir.lastIndexOf("google3/"); - if (lastIndex != -1) { - google3Path = currentDir.substring(0, lastIndex + "google3/".length()); - } - String resolvedImagePath = - Paths.get(google3Path, "third_party/py/google/genai/tests/data/dog.jpg") - .toString(); + String resolvedImagePath = "src/test/resources/logo.jpg"; com.google.genai.types.UploadToFileSearchStoreOperation opImage = client.fileSearchStores.uploadToFileSearchStore(