{"action":"created","comment":{"url":"https://api.github.com/repos/phenotips/phenotips/pulls/comments/34283256","id":34283256,"diff_hunk":"@@ -0,0 +1,199 @@\n+/*\n+ * See the NOTICE file distributed with this work for additional\n+ * information regarding copyright ownership.\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU Affero General Public License as published by\n+ * the Free Software Foundation, either version 3 of the License, or\n+ * (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU Affero General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Affero General Public License\n+ * along with this program.  If not, see http://www.gnu.org/licenses/\n+ */\n+package org.phenotips.data.rest.internal;\n+\n+import static org.mockito.Mockito.*;\n+\n+import com.xpn.xwiki.XWikiContext;\n+import net.sf.json.JSONObject;\n+import org.junit.Assert;\n+import org.junit.Before;\n+import org.junit.Rule;\n+import org.junit.Test;\n+import org.mockito.Mock;\n+import org.mockito.MockitoAnnotations;\n+import org.phenotips.data.PatientRepository;\n+import org.phenotips.data.rest.DomainObjectFactory;\n+import org.phenotips.data.rest.PatientsResource;\n+import org.phenotips.data.rest.model.Patient;\n+import org.phenotips.data.rest.model.Patients;\n+import org.xwiki.component.manager.ComponentLookupException;\n+import org.xwiki.component.manager.ComponentManager;\n+import org.xwiki.component.util.DefaultParameterizedType;\n+import org.xwiki.component.util.ReflectionUtils;\n+import org.xwiki.context.Execution;\n+import org.xwiki.context.ExecutionContext;\n+import org.xwiki.model.reference.DocumentReference;\n+import org.xwiki.model.reference.EntityReference;\n+import org.xwiki.model.reference.EntityReferenceResolver;\n+import org.xwiki.query.Query;\n+import org.xwiki.query.QueryException;\n+import org.xwiki.query.QueryManager;\n+import org.xwiki.query.internal.DefaultQuery;\n+import org.xwiki.rest.XWikiRestException;\n+import org.xwiki.security.authorization.AuthorizationManager;\n+import org.xwiki.security.authorization.Right;\n+import org.xwiki.test.mockito.MockitoComponentMockingRule;\n+import org.xwiki.users.User;\n+import org.xwiki.users.UserManager;\n+\n+import javax.inject.Provider;\n+import javax.ws.rs.WebApplicationException;\n+import javax.ws.rs.core.Response;\n+import javax.ws.rs.core.UriInfo;\n+import java.net.URI;\n+import java.net.URISyntaxException;\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+import org.slf4j.Logger;\n+\n+public class DefaultPatientsResourceImplTest {\n+\n+    @Rule\n+    public MockitoComponentMockingRule<PatientsResource> mocker =\n+        new MockitoComponentMockingRule<PatientsResource>(DefaultPatientsResourceImpl.class);\n+\n+    @Mock\n+    private User currentUser;\n+\n+    @Mock\n+    private Logger logger;\n+\n+    private PatientRepository repository;\n+\n+    private QueryManager queries;\n+\n+    private AuthorizationManager access;\n+\n+    private UserManager users;\n+\n+    private EntityReferenceResolver<EntityReference> currentResolver;\n+\n+    private DomainObjectFactory factory;\n+\n+    @Mock\n+    private Patient patient;\n+\n+    private URI uri;\n+\n+    @Mock\n+    private UriInfo uriInfo;\n+\n+    private DefaultPatientsResourceImpl patientsResource;\n+\n+    private XWikiContext context;\n+\n+\n+    @Before\n+    public void setUp() throws ComponentLookupException, URISyntaxException {\n+        MockitoAnnotations.initMocks(this);\n+        Execution execution = mock(Execution.class);\n+        ExecutionContext executionContext = mock(ExecutionContext.class);\n+        ComponentManager compManager = this.mocker.getInstance(ComponentManager.class, \"context\");\n+        when(compManager.getInstance(Execution.class)).thenReturn(execution);\n+        doReturn(executionContext).when(execution).getContext();\n+        doReturn(mock(XWikiContext.class)).when(executionContext).getProperty(\"xwikicontext\");\n+\n+        this.repository = this.mocker.getInstance(PatientRepository.class);\n+        this.users = this.mocker.getInstance(UserManager.class);\n+        this.access = this.mocker.getInstance(AuthorizationManager.class);\n+        this.patientsResource = (DefaultPatientsResourceImpl)this.mocker.getComponentUnderTest();\n+        this.logger = this.mocker.getMockedLogger();\n+        this.queries = this.mocker.getInstance(QueryManager.class);\n+        this.uri = new URI(\"http://uri\");\n+\n+        doReturn(this.uri).when(this.uriInfo).getBaseUri();\n+        doReturn(this.uri).when(this.uriInfo).getRequestUri();\n+        ReflectionUtils.setFieldValue(this.patientsResource, \"uriInfo\", this.uriInfo);\n+\n+        doReturn(\"00000001\").when(this.patient).getId();\n+        doReturn(this.currentUser).when(this.users).getCurrentUser();\n+        doReturn(null).when(this.currentUser).getProfileDocument();\n+    }\n+\n+    @Test\n+    public void addPatientUserDoesNotHaveAccess() throws XWikiRestException {\n+        WebApplicationException exception = new WebApplicationException();\n+        doReturn(false).when(this.access).hasAccess(Right.EDIT, null, mock(EntityReference.class));\n+        try {\n+            Response response = this.patientsResource.addPatient(\"\");\n+        }\n+        catch (WebApplicationException ex){\n+            exception = ex;\n+        }\n+        Assert.assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), exception.getResponse().getStatus());\n+        verify(this.logger).debug(\"Importing new patient from JSON via REST: {}\", \"\");\n+    }\n+\n+    @Test\n+    public void addNullPatient() throws XWikiRestException {\n+        doReturn(true).when(this.access).hasAccess(eq(Right.EDIT), any(DocumentReference.class), any(EntityReference.class));\n+        Response response = this.patientsResource.addPatient(null);\n+        Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());\n+        verify(this.logger).error(eq(\"Could not process remote matching request: {}\"), anyString(), anyObject());\n+    }\n+\n+    @Test\n+    public void addPatientAsJSON() throws XWikiRestException {\n+        doReturn(true).when(this.access).hasAccess(eq(Right.EDIT), any(DocumentReference.class), any(EntityReference.class));\n+        JSONObject json = new JSONObject();\n+        Response response = this.patientsResource.addPatient(json.toString());\n+        verify(this.logger).debug(\"Importing new patient from JSON via REST: {}\", json.toString());\n+    }\n+\n+    @Test\n+    public void listPatientsNullOrderField() throws XWikiRestException {\n+        WebApplicationException exception = new WebApplicationException();\n+        try {\n+            Patients result = this.patientsResource.listPatients(0, 30, null, \"asc\");\n+        }\n+        catch (WebApplicationException ex){","path":"components/patient-data/rest/src/test/java/org/phenotips/data/rest/internal/DefaultPatientsResourceImplTest.java","position":166,"original_position":166,"commit_id":"ba27b689fa45072a834769b2d35ed593cc10358f","original_commit_id":"ba27b689fa45072a834769b2d35ed593cc10358f","user":{"login":"DeanWay","id":11419228,"avatar_url":"https://avatars.githubusercontent.com/u/11419228?v=3","gravatar_id":"","url":"https://api.github.com/users/DeanWay","html_url":"https://github.com/DeanWay","followers_url":"https://api.github.com/users/DeanWay/followers","following_url":"https://api.github.com/users/DeanWay/following{/other_user}","gists_url":"https://api.github.com/users/DeanWay/gists{/gist_id}","starred_url":"https://api.github.com/users/DeanWay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DeanWay/subscriptions","organizations_url":"https://api.github.com/users/DeanWay/orgs","repos_url":"https://api.github.com/users/DeanWay/repos","events_url":"https://api.github.com/users/DeanWay/events{/privacy}","received_events_url":"https://api.github.com/users/DeanWay/received_events","type":"User","site_admin":false},"body":"when `null` is pass for the `orderField` parameter it will simply be translated to \"doc.name\". No exception will be thrown","created_at":"2015-07-09T17:55:16Z","updated_at":"2015-07-09T17:55:16Z","html_url":"https://github.com/phenotips/phenotips/pull/1810#discussion_r34283256","pull_request_url":"https://api.github.com/repos/phenotips/phenotips/pulls/1810","_links":{"self":{"href":"https://api.github.com/repos/phenotips/phenotips/pulls/comments/34283256"},"html":{"href":"https://github.com/phenotips/phenotips/pull/1810#discussion_r34283256"},"pull_request":{"href":"https://api.github.com/repos/phenotips/phenotips/pulls/1810"}}},"pull_request":{"url":"https://api.github.com/repos/phenotips/phenotips/pulls/1810","id":39521075,"html_url":"https://github.com/phenotips/phenotips/pull/1810","diff_url":"https://github.com/phenotips/phenotips/pull/1810.diff","patch_url":"https://github.com/phenotips/phenotips/pull/1810.patch","issue_url":"https://api.github.com/repos/phenotips/phenotips/issues/1810","number":1810,"state":"open","locked":false,"title":"DefaultPatientsResourceImpl tests","user":{"login":"tmarathe","id":9522666,"avatar_url":"https://avatars.githubusercontent.com/u/9522666?v=3","gravatar_id":"","url":"https://api.github.com/users/tmarathe","html_url":"https://github.com/tmarathe","followers_url":"https://api.github.com/users/tmarathe/followers","following_url":"https://api.github.com/users/tmarathe/following{/other_user}","gists_url":"https://api.github.com/users/tmarathe/gists{/gist_id}","starred_url":"https://api.github.com/users/tmarathe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmarathe/subscriptions","organizations_url":"https://api.github.com/users/tmarathe/orgs","repos_url":"https://api.github.com/users/tmarathe/repos","events_url":"https://api.github.com/users/tmarathe/events{/privacy}","received_events_url":"https://api.github.com/users/tmarathe/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-08T20:43:52Z","updated_at":"2015-07-09T17:55:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c9b2d386bd341274d6c7d993b25b3b4bc12a31c8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/phenotips/phenotips/pulls/1810/commits","review_comments_url":"https://api.github.com/repos/phenotips/phenotips/pulls/1810/comments","review_comment_url":"https://api.github.com/repos/phenotips/phenotips/pulls/comments{/number}","comments_url":"https://api.github.com/repos/phenotips/phenotips/issues/1810/comments","statuses_url":"https://api.github.com/repos/phenotips/phenotips/statuses/ba27b689fa45072a834769b2d35ed593cc10358f","head":{"label":"tmarathe:master","ref":"master","sha":"ba27b689fa45072a834769b2d35ed593cc10358f","user":{"login":"tmarathe","id":9522666,"avatar_url":"https://avatars.githubusercontent.com/u/9522666?v=3","gravatar_id":"","url":"https://api.github.com/users/tmarathe","html_url":"https://github.com/tmarathe","followers_url":"https://api.github.com/users/tmarathe/followers","following_url":"https://api.github.com/users/tmarathe/following{/other_user}","gists_url":"https://api.github.com/users/tmarathe/gists{/gist_id}","starred_url":"https://api.github.com/users/tmarathe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmarathe/subscriptions","organizations_url":"https://api.github.com/users/tmarathe/orgs","repos_url":"https://api.github.com/users/tmarathe/repos","events_url":"https://api.github.com/users/tmarathe/events{/privacy}","received_events_url":"https://api.github.com/users/tmarathe/received_events","type":"User","site_admin":false},"repo":{"id":36372006,"name":"phenotips","full_name":"tmarathe/phenotips","owner":{"login":"tmarathe","id":9522666,"avatar_url":"https://avatars.githubusercontent.com/u/9522666?v=3","gravatar_id":"","url":"https://api.github.com/users/tmarathe","html_url":"https://github.com/tmarathe","followers_url":"https://api.github.com/users/tmarathe/followers","following_url":"https://api.github.com/users/tmarathe/following{/other_user}","gists_url":"https://api.github.com/users/tmarathe/gists{/gist_id}","starred_url":"https://api.github.com/users/tmarathe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmarathe/subscriptions","organizations_url":"https://api.github.com/users/tmarathe/orgs","repos_url":"https://api.github.com/users/tmarathe/repos","events_url":"https://api.github.com/users/tmarathe/events{/privacy}","received_events_url":"https://api.github.com/users/tmarathe/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tmarathe/phenotips","description":"PhenoTips provides an easy-to-use Web interface and standardized database back-end for collecting clinical findings observed in patients with possible genetic disorders.","fork":true,"url":"https://api.github.com/repos/tmarathe/phenotips","forks_url":"https://api.github.com/repos/tmarathe/phenotips/forks","keys_url":"https://api.github.com/repos/tmarathe/phenotips/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tmarathe/phenotips/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tmarathe/phenotips/teams","hooks_url":"https://api.github.com/repos/tmarathe/phenotips/hooks","issue_events_url":"https://api.github.com/repos/tmarathe/phenotips/issues/events{/number}","events_url":"https://api.github.com/repos/tmarathe/phenotips/events","assignees_url":"https://api.github.com/repos/tmarathe/phenotips/assignees{/user}","branches_url":"https://api.github.com/repos/tmarathe/phenotips/branches{/branch}","tags_url":"https://api.github.com/repos/tmarathe/phenotips/tags","blobs_url":"https://api.github.com/repos/tmarathe/phenotips/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tmarathe/phenotips/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tmarathe/phenotips/git/refs{/sha}","trees_url":"https://api.github.com/repos/tmarathe/phenotips/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tmarathe/phenotips/statuses/{sha}","languages_url":"https://api.github.com/repos/tmarathe/phenotips/languages","stargazers_url":"https://api.github.com/repos/tmarathe/phenotips/stargazers","contributors_url":"https://api.github.com/repos/tmarathe/phenotips/contributors","subscribers_url":"https://api.github.com/repos/tmarathe/phenotips/subscribers","subscription_url":"https://api.github.com/repos/tmarathe/phenotips/subscription","commits_url":"https://api.github.com/repos/tmarathe/phenotips/commits{/sha}","git_commits_url":"https://api.github.com/repos/tmarathe/phenotips/git/commits{/sha}","comments_url":"https://api.github.com/repos/tmarathe/phenotips/comments{/number}","issue_comment_url":"https://api.github.com/repos/tmarathe/phenotips/issues/comments{/number}","contents_url":"https://api.github.com/repos/tmarathe/phenotips/contents/{+path}","compare_url":"https://api.github.com/repos/tmarathe/phenotips/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tmarathe/phenotips/merges","archive_url":"https://api.github.com/repos/tmarathe/phenotips/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tmarathe/phenotips/downloads","issues_url":"https://api.github.com/repos/tmarathe/phenotips/issues{/number}","pulls_url":"https://api.github.com/repos/tmarathe/phenotips/pulls{/number}","milestones_url":"https://api.github.com/repos/tmarathe/phenotips/milestones{/number}","notifications_url":"https://api.github.com/repos/tmarathe/phenotips/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tmarathe/phenotips/labels{/name}","releases_url":"https://api.github.com/repos/tmarathe/phenotips/releases{/id}","created_at":"2015-05-27T14:22:54Z","updated_at":"2015-05-27T14:22:59Z","pushed_at":"2015-07-09T14:09:17Z","git_url":"git://github.com/tmarathe/phenotips.git","ssh_url":"git@github.com:tmarathe/phenotips.git","clone_url":"https://github.com/tmarathe/phenotips.git","svn_url":"https://github.com/tmarathe/phenotips","homepage":"http://phenotips.org/","size":367923,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"phenotips:master","ref":"master","sha":"47743cc580ed90f8c9b38c99784896cea87f296a","user":{"login":"phenotips","id":4872353,"avatar_url":"https://avatars.githubusercontent.com/u/4872353?v=3","gravatar_id":"","url":"https://api.github.com/users/phenotips","html_url":"https://github.com/phenotips","followers_url":"https://api.github.com/users/phenotips/followers","following_url":"https://api.github.com/users/phenotips/following{/other_user}","gists_url":"https://api.github.com/users/phenotips/gists{/gist_id}","starred_url":"https://api.github.com/users/phenotips/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phenotips/subscriptions","organizations_url":"https://api.github.com/users/phenotips/orgs","repos_url":"https://api.github.com/users/phenotips/repos","events_url":"https://api.github.com/users/phenotips/events{/privacy}","received_events_url":"https://api.github.com/users/phenotips/received_events","type":"Organization","site_admin":false},"repo":{"id":2685841,"name":"phenotips","full_name":"phenotips/phenotips","owner":{"login":"phenotips","id":4872353,"avatar_url":"https://avatars.githubusercontent.com/u/4872353?v=3","gravatar_id":"","url":"https://api.github.com/users/phenotips","html_url":"https://github.com/phenotips","followers_url":"https://api.github.com/users/phenotips/followers","following_url":"https://api.github.com/users/phenotips/following{/other_user}","gists_url":"https://api.github.com/users/phenotips/gists{/gist_id}","starred_url":"https://api.github.com/users/phenotips/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phenotips/subscriptions","organizations_url":"https://api.github.com/users/phenotips/orgs","repos_url":"https://api.github.com/users/phenotips/repos","events_url":"https://api.github.com/users/phenotips/events{/privacy}","received_events_url":"https://api.github.com/users/phenotips/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/phenotips/phenotips","description":"PhenoTips provides an easy-to-use Web interface and standardized database back-end for collecting clinical findings observed in patients with possible genetic disorders.","fork":false,"url":"https://api.github.com/repos/phenotips/phenotips","forks_url":"https://api.github.com/repos/phenotips/phenotips/forks","keys_url":"https://api.github.com/repos/phenotips/phenotips/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phenotips/phenotips/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phenotips/phenotips/teams","hooks_url":"https://api.github.com/repos/phenotips/phenotips/hooks","issue_events_url":"https://api.github.com/repos/phenotips/phenotips/issues/events{/number}","events_url":"https://api.github.com/repos/phenotips/phenotips/events","assignees_url":"https://api.github.com/repos/phenotips/phenotips/assignees{/user}","branches_url":"https://api.github.com/repos/phenotips/phenotips/branches{/branch}","tags_url":"https://api.github.com/repos/phenotips/phenotips/tags","blobs_url":"https://api.github.com/repos/phenotips/phenotips/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phenotips/phenotips/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phenotips/phenotips/git/refs{/sha}","trees_url":"https://api.github.com/repos/phenotips/phenotips/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phenotips/phenotips/statuses/{sha}","languages_url":"https://api.github.com/repos/phenotips/phenotips/languages","stargazers_url":"https://api.github.com/repos/phenotips/phenotips/stargazers","contributors_url":"https://api.github.com/repos/phenotips/phenotips/contributors","subscribers_url":"https://api.github.com/repos/phenotips/phenotips/subscribers","subscription_url":"https://api.github.com/repos/phenotips/phenotips/subscription","commits_url":"https://api.github.com/repos/phenotips/phenotips/commits{/sha}","git_commits_url":"https://api.github.com/repos/phenotips/phenotips/git/commits{/sha}","comments_url":"https://api.github.com/repos/phenotips/phenotips/comments{/number}","issue_comment_url":"https://api.github.com/repos/phenotips/phenotips/issues/comments{/number}","contents_url":"https://api.github.com/repos/phenotips/phenotips/contents/{+path}","compare_url":"https://api.github.com/repos/phenotips/phenotips/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phenotips/phenotips/merges","archive_url":"https://api.github.com/repos/phenotips/phenotips/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phenotips/phenotips/downloads","issues_url":"https://api.github.com/repos/phenotips/phenotips/issues{/number}","pulls_url":"https://api.github.com/repos/phenotips/phenotips/pulls{/number}","milestones_url":"https://api.github.com/repos/phenotips/phenotips/milestones{/number}","notifications_url":"https://api.github.com/repos/phenotips/phenotips/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phenotips/phenotips/labels{/name}","releases_url":"https://api.github.com/repos/phenotips/phenotips/releases{/id}","created_at":"2011-11-01T05:55:21Z","updated_at":"2015-07-07T22:02:54Z","pushed_at":"2015-07-09T14:43:27Z","git_url":"git://github.com/phenotips/phenotips.git","ssh_url":"git@github.com:phenotips/phenotips.git","clone_url":"https://github.com/phenotips/phenotips.git","svn_url":"https://github.com/phenotips/phenotips","homepage":"http://phenotips.org/","size":432664,"stargazers_count":15,"watchers_count":15,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":311,"forks":12,"open_issues":311,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/phenotips/phenotips/pulls/1810"},"html":{"href":"https://github.com/phenotips/phenotips/pull/1810"},"issue":{"href":"https://api.github.com/repos/phenotips/phenotips/issues/1810"},"comments":{"href":"https://api.github.com/repos/phenotips/phenotips/issues/1810/comments"},"review_comments":{"href":"https://api.github.com/repos/phenotips/phenotips/pulls/1810/comments"},"review_comment":{"href":"https://api.github.com/repos/phenotips/phenotips/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/phenotips/phenotips/pulls/1810/commits"},"statuses":{"href":"https://api.github.com/repos/phenotips/phenotips/statuses/ba27b689fa45072a834769b2d35ed593cc10358f"}}}}