From a6ac1c158b80960b0124994c45c4241b65503f31 Mon Sep 17 00:00:00 2001 From: TheGeekTortoise Date: Thu, 14 Feb 2019 16:37:35 +0100 Subject: [PATCH] add AnnotationDomainTests --- .../test/http/AnnotationDomainAPI.groovy | 5 + .../be/cytomine/AnnotationDomainTests.groovy | 116 ++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 test/functional/be/cytomine/AnnotationDomainTests.groovy diff --git a/src/groovy/be/cytomine/test/http/AnnotationDomainAPI.groovy b/src/groovy/be/cytomine/test/http/AnnotationDomainAPI.groovy index f2739b095..da4ec99a7 100644 --- a/src/groovy/be/cytomine/test/http/AnnotationDomainAPI.groovy +++ b/src/groovy/be/cytomine/test/http/AnnotationDomainAPI.groovy @@ -69,6 +69,11 @@ class AnnotationDomainAPI extends DomainAPI { return doGET(URL, username, password) } + static def listByImageAndUsers(Long idImage,List 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) diff --git a/test/functional/be/cytomine/AnnotationDomainTests.groovy b/test/functional/be/cytomine/AnnotationDomainTests.groovy new file mode 100644 index 000000000..b9e6d9f79 --- /dev/null +++ b/test/functional/be/cytomine/AnnotationDomainTests.groovy @@ -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 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 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 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 + } + + +}