Skip to content

Commit

Permalink
add AnnotationDomainTests
Browse files Browse the repository at this point in the history
  • Loading branch information
geektortoise committed Feb 14, 2019
1 parent be3d1c3 commit a6ac1c1
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/groovy/be/cytomine/test/http/AnnotationDomainAPI.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class AnnotationDomainAPI extends DomainAPI {
return doGET(URL, username, password)
}

static def listByImageAndUsers(Long idImage,List<Long> idUsers, boolean includeAlgo, String username, String password) {
String URL = Infos.CYTOMINEURL+"api/annotation.json?users="+ idUsers.join(",") +"&image="+idImage+"&includeAlgo=$includeAlgo"
return doGET(URL, username, password)
}

static def listByProjectAndUsersWithoutTerm(Long id,Long idUser, Long idImage,String username, String password) {
String URL = Infos.CYTOMINEURL+"api/annotation.json?project=$id&noTerm=true&users=$idUser"+ (idImage? "&image="+idImage:"")
return doGET(URL, username, password)
Expand Down
116 changes: 116 additions & 0 deletions test/functional/be/cytomine/AnnotationDomainTests.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package be.cytomine

/*
* Copyright (c) 2009-2019. Authors: see NOTICE file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import be.cytomine.image.ImageInstance
import be.cytomine.ontology.AlgoAnnotation
import be.cytomine.ontology.UserAnnotation
import be.cytomine.project.Project
import be.cytomine.test.BasicInstanceBuilder
import be.cytomine.test.Infos
import be.cytomine.test.http.AnnotationDomainAPI
import grails.converters.JSON
import org.codehaus.groovy.grails.web.json.JSONObject


class AnnotationDomainTests {

void testSearchAnnotationFromUserAndJob() {
Project project = BasicInstanceBuilder.getProjectNotExist(true)
ImageInstance image = BasicInstanceBuilder.getImageInstanceNotExist(project, true)
UserAnnotation userAnnotation = BasicInstanceBuilder.getUserAnnotationNotExist(project, image, true)
AlgoAnnotation algoAnnotation = BasicInstanceBuilder.getAlgoAnnotationNotExist(image, true)
ArrayList<Long> users = new ArrayList<>();
users.add(userAnnotation.user.id)
users.add(algoAnnotation.user.id)

def result = AnnotationDomainAPI.listByImageAndUsers(image.id,users,false, Infos.SUPERADMINLOGIN,Infos.SUPERADMINPASSWORD)
assert 200 == result.code
def json = JSON.parse(result.data)
assert json instanceof JSONObject

assert json.collection.size() == 1

result = AnnotationDomainAPI.listByImageAndUsers(image.id,users,true, Infos.SUPERADMINLOGIN,Infos.SUPERADMINPASSWORD)
assert 200 == result.code
json = JSON.parse(result.data)
assert json instanceof JSONObject

//TODO : includeAlgo remove the parameter users in the RestAnnotationDomainController ==> change that
assert json.collection.size() == 1

users = users.reverse()
result = AnnotationDomainAPI.listByImageAndUsers(image.id,users,true, Infos.SUPERADMINLOGIN,Infos.SUPERADMINPASSWORD)
assert 200 == result.code
json = JSON.parse(result.data)
assert json instanceof JSONObject

//TODO : includeAlgo remove the parameter users in the RestAnnotationDomainController ==> change that
assert json.collection.size() == 1
}

void testSearchAnnotationFromUsers() {
Project project = BasicInstanceBuilder.getProjectNotExist(true)
ImageInstance image = BasicInstanceBuilder.getImageInstanceNotExist(project, true)
UserAnnotation userAnnotation = BasicInstanceBuilder.getUserAnnotationNotExist(project, image, true)
UserAnnotation userAnnotation2 = BasicInstanceBuilder.getUserAnnotationNotExist(project, image, true)
ArrayList<Long> users = new ArrayList<>();
users.add(userAnnotation.user.id)
users.add(userAnnotation2.user.id)

def result = AnnotationDomainAPI.listByImageAndUsers(image.id,users,false, Infos.SUPERADMINLOGIN,Infos.SUPERADMINPASSWORD)
assert 200 == result.code
def json = JSON.parse(result.data)
assert json instanceof JSONObject

assert json.collection.size() == 2

result = AnnotationDomainAPI.listByImageAndUsers(image.id,users,true, Infos.SUPERADMINLOGIN,Infos.SUPERADMINPASSWORD)
assert 200 == result.code
json = JSON.parse(result.data)
assert json instanceof JSONObject

//TODO : includeAlgo remove the parameter users in the RestAnnotationDomainController ==> change that
assert json.collection.size() == 0
}

void testSearchAnnotationFromJobs() {
Project project = BasicInstanceBuilder.getProjectNotExist(true)
ImageInstance image = BasicInstanceBuilder.getImageInstanceNotExist(project, true)
AlgoAnnotation algoAnnotation = BasicInstanceBuilder.getAlgoAnnotationNotExist(image, true)
AlgoAnnotation algoAnnotation2 = BasicInstanceBuilder.getAlgoAnnotationNotExist(image, true)
ArrayList<Long> users = new ArrayList<>();
users.add(algoAnnotation.user.id)
users.add(algoAnnotation2.user.id)

def result = AnnotationDomainAPI.listByImageAndUsers(image.id,users,false, Infos.SUPERADMINLOGIN,Infos.SUPERADMINPASSWORD)
assert 200 == result.code
def json = JSON.parse(result.data)
assert json instanceof JSONObject

//TODO : currently if only algo, we infer automatically the research. Do we want to keep this ?
assert json.collection.size() == 2

result = AnnotationDomainAPI.listByImageAndUsers(image.id,users,true, Infos.SUPERADMINLOGIN,Infos.SUPERADMINPASSWORD)
assert 200 == result.code
json = JSON.parse(result.data)
assert json instanceof JSONObject

assert json.collection.size() == 2
}


}

0 comments on commit a6ac1c1

Please sign in to comment.