Search in sources :

Example 11 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class BackendUsersResourceTest method testListFailure.

@Override
@Test
public void testListFailure() throws Exception {
    UriInfo uriInfo = setUpUriExpectations(null);
    setUpQueryExpectations(QUERY, FAILURE);
    collection.setUriInfo(uriInfo);
    try {
        getCollection();
        fail("expected WebApplicationException");
    } catch (WebApplicationException wae) {
        assertTrue(wae.getResponse().getEntity() instanceof Fault);
        assertEquals(mockl10n(FAILURE), ((Fault) wae.getResponse().getEntity()).getDetail());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Fault(org.ovirt.engine.api.model.Fault) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test) AbstractBackendCollectionResourceTest(org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest)

Example 12 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class BaseBackendResource method validateRange.

/**
 * Checks if the given value is within the range given by the {@code min} and {@code max} parameters. If the value
 * is {@code null} it will do nothing.
 *
 * @param name the name of the attribute
 * @param value the value of the attribute
 * @param min the min value of the range
 * @param max the max value of the range
 */
public void validateRange(String name, Integer value, int min, int max) {
    if (value != null && (value < min || value > max)) {
        Fault fault = new Fault();
        fault.setReason(localize(Messages.VALUE_OUT_OF_RANGE_REASON));
        fault.setDetail(localize(Messages.VALUE_OUT_OF_RANGE_DETAIL_TEMPLATE, value.toString(), name, String.valueOf(min), String.valueOf(max)));
        throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(fault).build());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Fault(org.ovirt.engine.api.model.Fault)

Example 13 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class AbstractBackendBaseTest method verifyIncompleteException.

protected void verifyIncompleteException(WebApplicationException wae, String type, String method, String... fields) {
    assertEquals(400, wae.getResponse().getStatus());
    Fault fault = (Fault) wae.getResponse().getEntity();
    assertNotNull(fault);
    assertEquals(INCOMPLETE_PARAMS_REASON_SERVER_LOCALE, fault.getReason());
    assertEquals(type + " " + Arrays.asList(fields) + INCOMPLETE_PARAMS_DETAIL_SERVER_LOCALE + method, fault.getDetail());
}
Also used : Fault(org.ovirt.engine.api.model.Fault)

Example 14 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class AbstractBackendBaseTest method verifyFault.

protected void verifyFault(WebApplicationException wae, String reason, Throwable t) {
    assertEquals(SERVER_ERROR, wae.getResponse().getStatus());
    assertTrue(wae.getResponse().getEntity() instanceof Fault);
    Fault fault = (Fault) wae.getResponse().getEntity();
    assertEquals(reason, fault.getReason());
    assertNotNull(fault.getDetail());
    assertTrue("expected detail to include: " + t.getMessage(), fault.getDetail().contains(t.getMessage()));
}
Also used : Fault(org.ovirt.engine.api.model.Fault)

Example 15 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class AbstractBackendCollectionResourceTest method testListFailure.

@Test
public void testListFailure() throws Exception {
    UriInfo uriInfo = setUpUriExpectations(null);
    setUpQueryExpectations("", FAILURE);
    collection.setUriInfo(uriInfo);
    try {
        getCollection();
        fail("expected WebApplicationException");
    } catch (WebApplicationException wae) {
        assertTrue(wae.getResponse().getEntity() instanceof Fault);
        assertEquals(mockl10n(FAILURE), ((Fault) wae.getResponse().getEntity()).getDetail());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Fault(org.ovirt.engine.api.model.Fault) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

Fault (org.ovirt.engine.api.model.Fault)42 WebApplicationException (javax.ws.rs.WebApplicationException)17 Test (org.junit.Test)15 UriInfo (javax.ws.rs.core.UriInfo)14 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)3 Request (javax.ws.rs.core.Request)3 AbstractBackendCollectionResourceTest (org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest)3 Action (org.ovirt.engine.api.model.Action)2 CreationStatus (org.ovirt.engine.api.model.CreationStatus)2 AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)2 Response (javax.ws.rs.core.Response)1 Creation (org.ovirt.engine.api.model.Creation)1 GlusterBrick (org.ovirt.engine.api.model.GlusterBrick)1 Vm (org.ovirt.engine.api.model.Vm)1 AbstractBackendSubResourceTest (org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest)1 InvalidValueException (org.ovirt.engine.api.utils.InvalidValueException)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 RemoveStorageDomainParameters (org.ovirt.engine.core.common.action.RemoveStorageDomainParameters)1 RunVmParams (org.ovirt.engine.core.common.action.RunVmParams)1