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());
}
}
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());
}
}
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());
}
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()));
}
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());
}
}
Aggregations