Search in sources :

Example 26 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by google.

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());
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) ResponseException(com.google.cloud.tools.jib.http.ResponseException) Test(org.junit.Test)

Example 27 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by google.

the class RegistryEndpointCallerTest method testNewRegistryErrorException_jsonErrorOutput.

@Test
public void testNewRegistryErrorException_jsonErrorOutput() {
    ResponseException httpException = Mockito.mock(ResponseException.class);
    Mockito.when(httpException.getContent()).thenReturn("{\"errors\": [{\"code\": \"MANIFEST_UNKNOWN\", \"message\": \"manifest unknown\"}]}");
    RegistryErrorException registryException = endpointCaller.newRegistryErrorException(httpException);
    Assert.assertSame(httpException, registryException.getCause());
    Assert.assertEquals("Tried to actionDescription but failed because: manifest unknown", registryException.getMessage());
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) ResponseException(com.google.cloud.tools.jib.http.ResponseException) Test(org.junit.Test)

Example 28 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by google.

the class RegistryEndpointCallerTest method testCall_unknown.

@Test
public void testCall_unknown() throws IOException, RegistryException {
    ResponseException responseException = mockResponseException(HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
    setUpRegistryResponse(responseException);
    try {
        endpointCaller.call();
        Assert.fail("Call should have failed");
    } catch (ResponseException ex) {
        Assert.assertSame(responseException, ex);
    }
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) ResponseException(com.google.cloud.tools.jib.http.ResponseException) Test(org.junit.Test)

Example 29 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by google.

the class RegistryEndpointCallerTest method verifyThrowsRegistryErrorException.

/**
 * Verifies that a response with {@code httpStatusCode} throws {@link
 * RegistryUnauthorizedException}.
 */
private void verifyThrowsRegistryErrorException(int httpStatusCode) throws IOException, RegistryException {
    ResponseException errorResponse = mockResponseException(httpStatusCode);
    Mockito.when(errorResponse.getContent()).thenReturn("{\"errors\":[{\"code\":\"code\",\"message\":\"message\"}]}");
    setUpRegistryResponse(errorResponse);
    try {
        endpointCaller.call();
        Assert.fail("Call should have failed");
    } catch (RegistryErrorException ex) {
        MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Tried to actionDescription but failed because: unknown error code: code (message)"));
    }
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) ResponseException(com.google.cloud.tools.jib.http.ResponseException)

Example 30 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by google.

the class RegistryEndpointCallerTest method testCall_credentialsForcedOverHttp.

@Test
public void testCall_credentialsForcedOverHttp() throws IOException, RegistryException {
    ResponseException unauthorizedException = mockResponseException(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
    setUpRegistryResponse(unauthorizedException);
    System.setProperty(JibSystemProperties.SEND_CREDENTIALS_OVER_HTTP, "true");
    try {
        endpointCaller.call();
        Assert.fail("Call should have failed");
    } catch (RegistryCredentialsNotSentException ex) {
        throw new AssertionError("should have sent credentials", ex);
    } catch (RegistryUnauthorizedException ex) {
        Assert.assertEquals("Unauthorized for serverUrl/imageName", ex.getMessage());
    }
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) ResponseException(com.google.cloud.tools.jib.http.ResponseException) RegistryUnauthorizedException(com.google.cloud.tools.jib.api.RegistryUnauthorizedException) Test(org.junit.Test)

Aggregations

ResponseException (com.google.cloud.tools.jib.http.ResponseException)44 Test (org.junit.Test)32 NoHttpResponseException (org.apache.http.NoHttpResponseException)18 RegistryUnauthorizedException (com.google.cloud.tools.jib.api.RegistryUnauthorizedException)8 ErrorResponseTemplate (com.google.cloud.tools.jib.registry.json.ErrorResponseTemplate)6 InsecureRegistryException (com.google.cloud.tools.jib.api.InsecureRegistryException)4 RegistryAuthenticationFailedException (com.google.cloud.tools.jib.api.RegistryAuthenticationFailedException)4 Request (com.google.cloud.tools.jib.http.Request)4 Response (com.google.cloud.tools.jib.http.Response)4 ErrorEntryTemplate (com.google.cloud.tools.jib.registry.json.ErrorEntryTemplate)4 IOException (java.io.IOException)4 JibContainer (com.google.cloud.tools.jib.api.JibContainer)2 RegistryException (com.google.cloud.tools.jib.api.RegistryException)2 BlobHttpContent (com.google.cloud.tools.jib.http.BlobHttpContent)2 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)2 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)2 RegistryCredentialsNotSentException (com.google.cloud.tools.jib.registry.RegistryCredentialsNotSentException)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 ExecutionException (java.util.concurrent.ExecutionException)2