use of com.google.cloud.tools.jib.http.ResponseException in project jib by GoogleContainerTools.
the class RegistryEndpointCallerTest method testNewRegistryErrorException_noOutputFromRegistry.
@Test
public void testNewRegistryErrorException_noOutputFromRegistry() {
ResponseException httpException = Mockito.mock(ResponseException.class);
// Registry returning null error output
Mockito.when(httpException.getContent()).thenReturn(null);
Mockito.when(httpException.getStatusCode()).thenReturn(404);
RegistryErrorException registryException = endpointCaller.newRegistryErrorException(httpException);
Assert.assertSame(httpException, registryException.getCause());
Assert.assertEquals("Tried to actionDescription but failed because: registry returned error code 404 " + "but did not return any details; possible causes include invalid or wrong reference, or proxy/firewall/VPN interfering \n", registryException.getMessage());
}
use of com.google.cloud.tools.jib.http.ResponseException in project jib by GoogleContainerTools.
the class RegistryEndpointCallerTest method testNewRegistryErrorException_nonJsonErrorOutput.
@Test
public void testNewRegistryErrorException_nonJsonErrorOutput() {
ResponseException httpException = Mockito.mock(ResponseException.class);
// Registry returning non-structured error output
Mockito.when(httpException.getContent()).thenReturn(">>>>> (404) page not found <<<<<");
Mockito.when(httpException.getStatusCode()).thenReturn(404);
RegistryErrorException registryException = endpointCaller.newRegistryErrorException(httpException);
Assert.assertSame(httpException, registryException.getCause());
Assert.assertEquals("Tried to actionDescription but failed because: registry returned error code 404; " + "possible causes include invalid or wrong reference. Actual error output follows:\n" + ">>>>> (404) page not found <<<<<\n", registryException.getMessage());
}
use of com.google.cloud.tools.jib.http.ResponseException in project jib by GoogleContainerTools.
the class RegistryEndpointCallerTest method verifyThrowsRegistryUnauthorizedException.
/**
* Verifies that a response with {@code httpStatusCode} throws {@link
* RegistryUnauthorizedException}.
*/
private void verifyThrowsRegistryUnauthorizedException(int httpStatusCode) throws IOException, RegistryException {
ResponseException responseException = mockResponseException(httpStatusCode);
setUpRegistryResponse(responseException);
try {
endpointCaller.call();
Assert.fail("Call should have failed");
} catch (RegistryUnauthorizedException ex) {
Assert.assertEquals("serverUrl/imageName", ex.getImageReference());
Assert.assertSame(responseException, ex.getCause());
}
}
use of com.google.cloud.tools.jib.http.ResponseException in project jib by GoogleContainerTools.
the class BlobCheckerTest method testHandleHttpResponseException_hasOtherErrors.
@Test
public void testHandleHttpResponseException_hasOtherErrors() throws IOException {
ResponseException mockResponseException = Mockito.mock(ResponseException.class);
Mockito.when(mockResponseException.getStatusCode()).thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
ErrorResponseTemplate emptyErrorResponseTemplate = new ErrorResponseTemplate().addError(new ErrorEntryTemplate(ErrorCodes.BLOB_UNKNOWN.name(), "some message")).addError(new ErrorEntryTemplate(ErrorCodes.MANIFEST_UNKNOWN.name(), "some message"));
Mockito.when(mockResponseException.getContent()).thenReturn(JsonTemplateMapper.toUtf8String(emptyErrorResponseTemplate));
try {
testBlobChecker.handleHttpResponseException(mockResponseException);
Assert.fail("Non-BLOB_UNKNOWN errors should not be handled");
} catch (ResponseException ex) {
Assert.assertEquals(mockResponseException, ex);
}
}
Aggregations