use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class CompletenessAssertorTest method verifyIncompleteException.
private void verifyIncompleteException(WebApplicationException wae, String type, String... fields) {
assertEquals(400, wae.getResponse().getStatus());
Fault fault = (Fault) wae.getResponse().getEntity();
assertNotNull(fault);
assertEquals("Incomplete parameters", fault.getReason());
String method = new Throwable().getStackTrace()[1].getMethodName();
assertEquals(type + " " + Arrays.asList(fields) + " required for " + method, fault.getDetail());
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class MutabilityAssertor method imposeConstraints.
/**
* Impose immutability constraints.
*
* @param <T> representation type
* @param strict array of strictly immutable field names
* @param incoming incoming representation
* @param existing existing representation
* @param reason the fault reason
* @param detail the fault detail
* @return error Response if appropriate
*/
public static <T extends BaseResource> Response imposeConstraints(String[] strict, T incoming, T existing, String reason, String detail) {
for (String s : strict) {
String field = capitalize(s);
if (isSet(incoming, field) && different(incoming, existing, field)) {
Fault fault = new Fault();
fault.setReason(reason);
fault.setDetail(MessageFormat.format(detail, s));
return Response.status(BROKEN_CONSTRAINT_STATUS).entity(fault).build();
}
}
return null;
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class Ipv4BootProtocolMapper method fault.
private static Fault fault(String reason, String detail) {
Fault fault = new Fault();
fault.setReason(reason);
fault.setDetail(detail);
return fault;
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class BackendStorageDomainResource method remove.
@Override
public Response remove() {
boolean destroy = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, DESTROY, true, false);
get();
if (destroy) {
StorageDomainParametersBase parameters = new StorageDomainParametersBase(guid);
return performAction(ActionType.ForceRemoveStorageDomain, parameters);
} else {
String host = ParametersHelper.getParameter(httpHeaders, uriInfo, HOST);
if (host == null) {
Fault fault = new Fault();
fault.setReason("host parameter is missing");
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(fault).build());
}
boolean format = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, FORMAT, true, false);
Guid hostId = getHostId(host);
RemoveStorageDomainParameters parameters = new RemoveStorageDomainParameters(guid);
parameters.setVdsId(hostId);
parameters.setDoFormat(format);
return performAction(ActionType.RemoveStorageDomain, parameters);
}
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class BackendGroupsResourceTest method testListFailure.
@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());
}
}
Aggregations