diff --git a/pom.xml b/pom.xml
index fa05b8d..db4063d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,6 +9,16 @@
1.0-SNAPSHOT
+
+ cytomine
+ Cytomine
+ info@cytomine.coop
+
+
+ geektortoise
+ Renaud Hoyoux
+ Renaud.Hoyoux@cytomine.coop
+
lrollus
Loïc ROLLUS
@@ -90,6 +100,12 @@
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.0.0
+ test
+
@@ -104,7 +120,23 @@
1.7
-
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.19.1
+
+
+ org.junit.platform
+ junit-platform-surefire-provider
+ 1.0.1
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.0.0
+
+
+
diff --git a/src/main/java/be/cytomine/client/Cytomine.java b/src/main/java/be/cytomine/client/Cytomine.java
index b7d13be..6b6f824 100644
--- a/src/main/java/be/cytomine/client/Cytomine.java
+++ b/src/main/java/be/cytomine/client/Cytomine.java
@@ -1110,6 +1110,12 @@ public SoftwareCollection getSoftwares() throws CytomineException {
return fetchCollection(softwares);
}
+ public Software getSoftware(Long id) throws CytomineException {
+ Software software = new Software();
+ software.set("id",id);
+ return fetchModel(software);
+ }
+
public ProcessingServer addProcessingServer(String url) throws CytomineException {
ProcessingServer processingServer = new ProcessingServer();
processingServer.set("url", url);
@@ -1494,10 +1500,6 @@ public void deleteUploadedFile(Long idUploadedFile) throws CytomineException {
deleteModel(uploadedFile);
}
- public String clearAbstractImageProperties(Long idImage) throws CytomineException {
- return doPost("/api/abstractimage/" + idImage + "/properties/clear.json", "");
- }
-
public UploadedFile editUploadedFile(Long id, int status, boolean converted, Long idParent) throws CytomineException {
UploadedFile uploadedFile = getUploadedFile(id);
uploadedFile.set("status", status);
@@ -1683,6 +1685,15 @@ public void indexToRetrieval(Long id, Long container, String url) throws Cytomin
doPost("/retrieval-web/api/resource.json", data);
}
+ public void executeJob(Long idJob) throws CytomineException {
+ doPost("/api/job/"+idJob+"/execute.json", "");
+ }
+
+ public JSONObject getSimilaritiesByRetrieval(Long idAnnotation) throws CytomineException {
+ String response = doGet("/api/annotation/"+idAnnotation+"/retrieval.json");
+ return (JSONObject) JSONValue.parse(response);
+ }
+
public AmqpQueueCollection getAmqpQueue() throws CytomineException {
AmqpQueueCollection queues = new AmqpQueueCollection(offset, max);
return fetchCollection(queues);
diff --git a/src/main/java/be/cytomine/client/sample/SoftwareExample.java b/src/main/java/be/cytomine/client/sample/SoftwareExample.java
index 30c0795..6389440 100644
--- a/src/main/java/be/cytomine/client/sample/SoftwareExample.java
+++ b/src/main/java/be/cytomine/client/sample/SoftwareExample.java
@@ -212,7 +212,7 @@ public static void addSoftwareComputeAreaOld(Cytomine cytomine) throws Exception
}
}
- public static void addSoftwareComputeTermArea(Cytomine cytomine) throws Exception {
+ public static void addSoftwareComputeTermArea(Cytomine cytomine) {
try {
Software software = cytomine.addSoftware("ComputeTermArea", "createRabbitJobService", "DownloadFiles",
"groovy -cp lib/jars/Cytomine-client-java.jar algo/computeTermArea.groovy ");
diff --git a/src/test/java/functional/FunctionalTest.java b/src/test/java/functional/FunctionalTest.java
new file mode 100644
index 0000000..4ade73c
--- /dev/null
+++ b/src/test/java/functional/FunctionalTest.java
@@ -0,0 +1,203 @@
+package functional;
+
+/*
+ * Copyright (c) 2009-2018. 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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import be.cytomine.client.Cytomine;
+import be.cytomine.client.CytomineException;
+import be.cytomine.client.collections.SoftwareCollection;
+import be.cytomine.client.models.*;
+import be.cytomine.client.sample.SoftwareExample;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.junit.jupiter.api.*;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+class FunctionalTest {
+
+ private static final Logger log = Logger.getLogger(FunctionalTest.class);
+ private static String host;
+ private static String publicKey;
+ private static String privateKey;
+ private static Cytomine cytomine;
+
+ private static Project project;
+ private static ImageInstance image;
+ private static Term term;
+ @BeforeAll
+ static void initAll() throws CytomineException {
+ BasicConfigurator.configure();
+ PropertyConfigurator.configure("log4j.properties");
+
+ host = System.getProperty("host");
+ assertNotNull(host, "host, publicKey, privateKey");
+ publicKey = System.getProperty("publicKey");
+ assertNotNull(publicKey, "host, publicKey, privateKey");
+ privateKey = System.getProperty("privateKey");
+ assertNotNull(privateKey, "host, publicKey, privateKey");
+
+ log.info("Connection to cytomine...");
+ cytomine = new Cytomine(host,publicKey,privateKey);
+
+ Ontology ontology = cytomine.addOntology(UUID.randomUUID().toString());
+ project = cytomine.addProject(UUID.randomUUID().toString(),ontology.getId());
+ term = cytomine.addTerm("testTerm","#000000",ontology.getId());
+ }
+
+ @BeforeEach
+ void init() {
+ }
+
+ @Test
+ void getCurrentUser() {
+ try {
+ log.info("getCurrentUser");
+ assertEquals(cytomine.getCurrentUser().get("username"), "admin", "Not the expected user");
+ } catch (CytomineException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ void upload() throws CytomineException {
+ if(image != null) return;
+ log.info("upload");
+
+ assert cytomine.getStorages().size() > 0;
+ Storage storage = cytomine.getStorages().get(0);
+
+ int nbImages = cytomine.getImageInstances(project.getId()).size();
+ assert nbImages == 0;
+
+ Cytomine cytomineUpload = new Cytomine(System.getProperty("uploadUrl"), publicKey, privateKey);
+
+ JSONArray response = cytomineUpload.uploadImage(System.getProperty("imgPath"), project.getId(), storage.getId(), host, null, true);
+
+ assert response.size() == 1;
+ assert response.get(0) instanceof JSONObject;
+
+ JSONObject test = (JSONObject) response.get(0);
+ assert test.get("status") instanceof Long;
+ assert (Long) test.get("status") == 200;
+
+ nbImages = cytomine.getImageInstances(project.getId()).size();
+ assert nbImages == 1;
+ image = cytomine.getImageInstances(project.getId()).get(0);
+ }
+
+ @Test
+ void retrieval() throws CytomineException {
+ if(image == null) upload();
+
+ log.info("retrieval");
+
+ Long width = Long.parseLong(image.get("width").toString());
+ Long height = Long.parseLong(image.get("height").toString());
+
+ String polygon = "POLYGON (("+((width/2)-20)+" "+((height/2)-20)+", "+((width/2)-20)+" "+((height/2)+20)+", "+((width/2)+20)+" "+((height/2)+20)+", "+((width/2)+20)+" "+((height/2)-20)+", "+((width/2)-20)+" "+((height/2)-20)+"))";
+
+ List terms = new ArrayList<>();
+ terms.add(term.getId());
+
+ Annotation annot = cytomine.addAnnotationWithTerms(polygon, image.getId(),terms);
+ try {
+ Thread.sleep(2500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ Annotation annot2 = cytomine.addAnnotation(polygon, image.getId());
+
+ try {
+ Thread.sleep(2500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ JSONObject response = cytomine.getSimilaritiesByRetrieval(annot2.getId());
+
+ assertEquals(((JSONObject)((JSONArray) response.get("annotation")).get(0)).get("id"), annot.getId(), "Annotation is not returned by retrieval");
+ assertEquals(((JSONObject)((JSONArray) response.get("term")).get(0)).get("id"), term.getId(), "Term is not returned by retrieval");
+ }
+
+ @Test
+ void runExistingSoftware() throws CytomineException {
+ if(image == null) upload();
+
+ log.info("runSoftware");
+
+ SoftwareExample.addSoftwareComputeTermArea(cytomine);
+
+ SoftwareCollection softwares = cytomine.getSoftwares();
+
+ Long computeTermAreaId = null;
+ Long termsParamId = null;
+ Long imagesParamId = null;
+ for(int i=0;i