use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class JpaSnapshotDao method doRemove.
@Transactional
protected void doRemove(String snapshotId) throws NotFoundException {
final EntityManager manager = managerProvider.get();
final SnapshotImpl snapshot = manager.find(SnapshotImpl.class, snapshotId);
if (snapshot == null) {
throw new NotFoundException(format("Snapshot with id '%s' doesn't exist", snapshotId));
}
manager.remove(snapshot);
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class JpaSnapshotDao method getSnapshot.
@Override
@Transactional
public SnapshotImpl getSnapshot(String workspaceId, String envName, String machineName) throws NotFoundException, SnapshotException {
requireNonNull(workspaceId, "Required non-null workspace id");
requireNonNull(envName, "Required non-null environment name");
requireNonNull(machineName, "Required non-null machine name");
try {
return managerProvider.get().createNamedQuery("Snapshot.getByMachine", SnapshotImpl.class).setParameter("workspaceId", workspaceId).setParameter("envName", envName).setParameter("machineName", machineName).getSingleResult();
} catch (NoResultException x) {
throw new NotFoundException(format("Snapshot for machine '%s:%s:%s' doesn't exist", workspaceId, envName, machineName));
} catch (RuntimeException x) {
throw new SnapshotException(x.getLocalizedMessage(), x);
}
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class FactoryServiceTest method shouldThrowNotFoundExceptionWhenFactoryIsNotExist.
@Test
public void shouldThrowNotFoundExceptionWhenFactoryIsNotExist() throws Exception {
final String errMessage = format("Factory with id %s is not found", FACTORY_ID);
doThrow(new NotFoundException(errMessage)).when(factoryManager).getById(anyString());
final Response response = given().expect().statusCode(404).when().get(SERVICE_PATH + "/" + FACTORY_ID);
assertEquals(getFromResponse(response, ServiceError.class).getMessage(), errMessage);
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class FactoryServiceTest method shouldThrowNotFoundExceptionWhenFactoryImageWithGivenIdentifierIsNotExist.
@Test
public void shouldThrowNotFoundExceptionWhenFactoryImageWithGivenIdentifierIsNotExist() throws Exception {
final String errMessage = "Image with name " + IMAGE_NAME + " is not found";
when(factoryManager.getFactoryImages(FACTORY_ID, IMAGE_NAME)).thenThrow(new NotFoundException(errMessage));
final Response response = given().expect().statusCode(404).when().get(SERVICE_PATH + "/" + FACTORY_ID + "/image?imgId=" + IMAGE_NAME);
assertEquals(getFromResponse(response, ServiceError.class).getMessage(), errMessage);
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class FactoryServiceTest method shouldResponse404OnGetSnippetIfFactoryDoesNotExist.
@Test
public void shouldResponse404OnGetSnippetIfFactoryDoesNotExist() throws Exception {
// given
doThrow(new NotFoundException("Factory URL with id " + FACTORY_ID + " is not found.")).when(factoryManager).getFactorySnippet(anyString(), anyString(), any());
// when, then
final Response response = given().expect().statusCode(404).when().get(SERVICE_PATH + "/" + FACTORY_ID + "/snippet?type=url");
assertEquals(getFromResponse(response, ServiceError.class).getMessage(), "Factory URL with id " + FACTORY_ID + " is not found.");
}
Aggregations