Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
added exception status checks
Browse files Browse the repository at this point in the history
  • Loading branch information
tmarathe committed Jul 10, 2015
1 parent 1f1875b commit 080d9f4
Showing 1 changed file with 23 additions and 4 deletions.
Expand Up @@ -21,6 +21,7 @@
import org.xwiki.context.ExecutionContext;
import org.xwiki.model.reference.EntityReference;
import org.xwiki.model.reference.EntityReferenceResolver;
import org.xwiki.query.QueryException;
import org.xwiki.query.QueryManager;
import org.xwiki.rest.XWikiRestException;
import org.xwiki.security.authorization.AuthorizationManager;
Expand All @@ -43,8 +44,11 @@ public class DefaultPatientsResourceImplTest {
@Mock
private User currentUser;

@Mock
private Logger logger;

private PatientRepository repository;

private QueryManager queries;
private AuthorizationManager access;
private UserManager users;
Expand Down Expand Up @@ -73,6 +77,7 @@ public void setUp() throws ComponentLookupException {
this.access = this.mocker.getInstance(AuthorizationManager.class);
this.patientsResource = (DefaultPatientsResourceImpl)this.mocker.getComponentUnderTest();
this.logger = this.mocker.getMockedLogger();
this.queries = this.mocker.getInstance(QueryManager.class);

doReturn(this.currentUser).when(this.users).getCurrentUser();
doReturn(null).when(this.currentUser).getProfileDocument();
Expand All @@ -90,7 +95,6 @@ public void addNullPatient() throws XWikiRestException {
doReturn(true).when(this.access).hasAccess(Right.EDIT, null, mock(EntityReference.class));
Response response = this.patientsResource.addPatient(null);
verify(this.logger).error("Could not process remote matching request: {}", anyString(), anyObject());
Assert.assertEquals(Response.status(Response.Status.BAD_REQUEST).build(), response);
}

@Test
Expand All @@ -101,10 +105,17 @@ public void addPatientAsJSON() throws XWikiRestException {
System.out.println(response);
}

@Test(expected = WebApplicationException.class)
@Test
public void listPatientsNullOrderField() throws XWikiRestException {
Patients result = this.patientsResource.listPatients(0, 30, null, "asc");
verify(this.logger).error("Failed to list patients: {}", anyString(), anyObject());
WebApplicationException exception = new WebApplicationException();
try {
Patients result = this.patientsResource.listPatients(0, 30, null, "asc");
}
catch (WebApplicationException ex){
exception = ex;
}
Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), exception.getResponse().getStatus());
verify(this.logger).error(eq("Failed to list patients: {}"), anyString(), anyObject());
}

@Test(expected = WebApplicationException.class)
Expand All @@ -113,4 +124,12 @@ public void listPatientsNullOrder() throws XWikiRestException {
verify(this.logger).error("Failed to list patients: {}", anyString(), anyObject());
}

@Test
public void listPatientsDefaultBehaviour() throws WebApplicationException, XWikiRestException, QueryException {
Patients result = this.patientsResource.listPatients(0, 30, "id", "asc");
verify(this.queries.createQuery("select doc.fullName, p.external_id, doc.creator, doc.creationDate, doc.version, doc.author, doc.date"
+ " from Document doc, doc.object(PhenoTips.PatientClass) p where doc.name <> :t order by "
+ "doc.name" + " asc", "xwql"));
}

}

0 comments on commit 080d9f4

Please sign in to comment.