@Test public void creatingPatientFails() { JSONObject json = new JSONObject(); Exception exception = new NullPointerException(); doReturn(true).when(this.access).hasAccess(any(User.class), eq(Right.EDIT), any(EntityReference.class)); doThrow(exception).when(this.repository).create(); Response response = this.patientsResource.add(json.toString()); Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); verify(this.logger).error("Could not process patient creation request: {}", exception.getMessage(), exception); }
@Override public Response add(final String json) { this.slf4Jlogger.debug("Importing new patient from JSON via REST: {}", json); final User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.EDIT, this.currentResolver.resolve(Patient.DEFAULT_DATA_SPACE, EntityType.SPACE))) { throw new WebApplicationException(Status.UNAUTHORIZED); } try { final Response response; if (json != null) { response = json.startsWith("[") ? addPatients(json) : addPatient(json); } else { response = buildCreatedResponse(this.repository.create()); } return response; } catch (Exception ex) { this.slf4Jlogger.error("Could not process patient creation request: {}", ex.getMessage(), ex); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } }
DefaultPatientsResourceImpl extends XWikiResource implements PatientsResource { @Override public Response add(final String json) { this.slf4Jlogger.debug("Importing new patient from JSON via REST: {}", json); final User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.EDIT, this.currentResolver.resolve(Patient.DEFAULT_DATA_SPACE, EntityType.SPACE))) { throw new WebApplicationException(Status.UNAUTHORIZED); } try { final Response response; if (json != null) { response = json.startsWith("[") ? addPatients(json) : addPatient(json); } else { response = buildCreatedResponse(this.repository.create()); } return response; } catch (Exception ex) { this.slf4Jlogger.error("Could not process patient creation request: {}", ex.getMessage(), ex); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } } }
DefaultPatientsResourceImpl extends XWikiResource implements PatientsResource { @Override public Response add(final String json) { this.slf4Jlogger.debug("Importing new patient from JSON via REST: {}", json); final User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.EDIT, this.currentResolver.resolve(Patient.DEFAULT_DATA_SPACE, EntityType.SPACE))) { throw new WebApplicationException(Status.UNAUTHORIZED); } try { final Response response; if (json != null) { response = json.startsWith("[") ? addPatients(json) : addPatient(json); } else { response = buildCreatedResponse(this.repository.create()); } return response; } catch (Exception ex) { this.slf4Jlogger.error("Could not process patient creation request: {}", ex.getMessage(), ex); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } }  }
DefaultPatientsResourceImpl extends XWikiResource implements PatientsResource { @Override public Response add(final String json) { this.slf4Jlogger.debug("Importing new patient from JSON via REST: {}", json); final User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.EDIT, this.currentResolver.resolve(Patient.DEFAULT_DATA_SPACE, EntityType.SPACE))) { throw new WebApplicationException(Status.UNAUTHORIZED); } try { final Response response; if (json != null) { response = json.startsWith("[") ? addPatients(json) : addPatient(json); } else { response = buildCreatedResponse(this.repository.create()); } return response; } catch (Exception ex) { this.slf4Jlogger.error("Could not process patient creation request: {}", ex.getMessage(), ex); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } }  @Override Response add(final String json); @Override Patients listPatients(Integer start, Integer number, String orderField, String order); }
DefaultPatientsResourceImpl extends XWikiResource implements PatientsResource { @Override public Response add(final String json) { this.slf4Jlogger.debug("Importing new patient from JSON via REST: {}", json); final User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.EDIT, this.currentResolver.resolve(Patient.DEFAULT_DATA_SPACE, EntityType.SPACE))) { throw new WebApplicationException(Status.UNAUTHORIZED); } try { final Response response; if (json != null) { response = json.startsWith("[") ? addPatients(json) : addPatient(json); } else { response = buildCreatedResponse(this.repository.create()); } return response; } catch (Exception ex) { this.slf4Jlogger.error("Could not process patient creation request: {}", ex.getMessage(), ex); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } }  @Override Response add(final String json); @Override Patients listPatients(Integer start, Integer number, String orderField, String order);  }