Add unit test for Unauthenticated error unit.
@@ -266,5 +266,37 @@ public class CustomModelDownloadServiceTest {
equalTo(INSTALLATION_TOKEN)));
}
- // TODO(annz) add test matching bad token response when BE is ready.
+ @Test
+ public void downloadService_unauthenticatedToken() throws Exception {
+ String downloadPath =
+ String.format(CustomModelDownloadService.DOWNLOAD_MODEL_REGEX, "", PROJECT_ID, MODEL_NAME);
+ stubFor(
+ get(urlEqualTo(downloadPath))
+ .withHeader(
+ CustomModelDownloadService.INSTALLATIONS_AUTH_TOKEN_HEADER,
+ equalTo(INSTALLATION_TOKEN))
+ .withHeader(
+ CustomModelDownloadService.CONTENT_TYPE,
+ equalTo(CustomModelDownloadService.APPLICATION_JSON))
+ .withHeader(CustomModelDownloadService.IF_NONE_MATCH_HEADER_KEY, equalTo(MODEL_HASH))
+ .willReturn(
+ aResponse()
+ .withStatus(401) // not found
+ .withBody(
+ "{\"status\":\"UNAUTHENTICATED\",\"message\":\"Request is missing required authentication credential.\"}")));
+
+ CustomModelDownloadService service =
+ new CustomModelDownloadService(
+ installationsApiMock, directExecutor, API_KEY, TEST_ENDPOINT);
+
+ Task<CustomModel> modelTask = service.getCustomModelDetails(PROJECT_ID, MODEL_NAME, MODEL_HASH);
+
+ Assert.assertTrue(modelTask.getException().getMessage().contains("401"));
+
+ verify(
+ getRequestedFor(urlEqualTo(downloadPath))
+ .withHeader(
+ CustomModelDownloadService.INSTALLATIONS_AUTH_TOKEN_HEADER,
+ equalTo(INSTALLATION_TOKEN)));
+ }
}
