2022-02-02 18:34:32 +01:00
|
|
|
package org.gcube.application.geoportal.clients;
|
|
|
|
|
2022-08-31 18:06:19 +02:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.bson.Document;
|
2022-03-07 13:59:24 +01:00
|
|
|
import org.gcube.application.geoportal.client.DefaultDocumentsClient;
|
2022-08-31 18:06:19 +02:00
|
|
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
2022-03-04 14:23:20 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
2022-03-10 18:15:10 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
2022-02-04 17:45:47 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
2022-03-04 14:23:20 +01:00
|
|
|
import org.gcube.application.geoportal.common.rest.Projects;
|
2022-02-24 18:09:30 +01:00
|
|
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
2022-02-02 18:34:32 +01:00
|
|
|
import org.junit.Test;
|
2022-04-22 11:04:25 +02:00
|
|
|
import sun.net.www.content.text.Generic;
|
2022-02-02 18:34:32 +01:00
|
|
|
|
2022-02-04 17:45:47 +01:00
|
|
|
import java.rmi.RemoteException;
|
2022-08-31 18:06:19 +02:00
|
|
|
import java.time.LocalDateTime;
|
2022-02-04 17:45:47 +01:00
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
2022-02-02 18:34:32 +01:00
|
|
|
|
2022-02-04 17:45:47 +01:00
|
|
|
import static junit.framework.TestCase.assertTrue;
|
2022-03-07 13:59:24 +01:00
|
|
|
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.*;
|
2022-08-31 18:06:19 +02:00
|
|
|
import static org.gcube.application.geoportal.client.utils.Serialization.write;
|
2022-02-24 18:09:30 +01:00
|
|
|
import static org.junit.Assume.assumeTrue;
|
2022-02-02 18:34:32 +01:00
|
|
|
|
2022-08-31 18:06:19 +02:00
|
|
|
@Slf4j
|
2022-04-22 11:04:25 +02:00
|
|
|
public class ProfiledDocumentsTest<M extends Project,C extends Projects<M>> extends GenericUseCases {
|
2022-02-04 17:45:47 +01:00
|
|
|
|
2022-04-22 11:04:25 +02:00
|
|
|
// protected String getProfileID(){return "basic";}
|
2022-02-04 17:45:47 +01:00
|
|
|
|
2022-04-22 11:04:25 +02:00
|
|
|
// protected C getClient(){
|
|
|
|
// return (C) customModel(getProfileID(), Project.class, DefaultDocumentsClient.class).build();
|
|
|
|
// }
|
2022-02-02 18:34:32 +01:00
|
|
|
|
|
|
|
|
2022-08-31 18:06:19 +02:00
|
|
|
@Test
|
|
|
|
public void registerNew() throws RemoteException, JsonProcessingException {
|
|
|
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
|
|
Projects<M> client = (Projects<M>) getClient();
|
|
|
|
|
|
|
|
Document theDoc= Document.parse("{\n" +
|
|
|
|
"\"posizionamentoScavo\" :{\n" +
|
|
|
|
"\t\"titolo\" : \"mio titolo\"}}");
|
|
|
|
|
|
|
|
theDoc.put("startTime", LocalDateTime.now());
|
|
|
|
|
|
|
|
Project p =client.createNew(theDoc);
|
|
|
|
|
|
|
|
log.debug("Registered project (AS JSON) : {}", write(p));
|
|
|
|
}
|
|
|
|
|
2022-02-02 18:34:32 +01:00
|
|
|
@Test
|
|
|
|
public void getConfiguration() throws Exception {
|
2022-02-24 18:09:30 +01:00
|
|
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
2022-03-04 14:23:20 +01:00
|
|
|
Projects<M> client = (Projects<M>) getClient();
|
2022-02-04 17:45:47 +01:00
|
|
|
Configuration config=client.getConfiguration();
|
|
|
|
System.out.println("Configuration is "+ config);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void list() throws Exception {
|
2022-02-24 18:09:30 +01:00
|
|
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
2022-03-04 14:23:20 +01:00
|
|
|
Projects<M> client = (Projects<M>) getClient();
|
2022-02-04 17:45:47 +01:00
|
|
|
AtomicLong counter=new AtomicLong(0);
|
|
|
|
client.query(new QueryRequest()).forEachRemaining( M -> counter.incrementAndGet());
|
|
|
|
System.out.println("Found "+counter.get()+" elements");
|
|
|
|
System.out.println("Getting JSON ");
|
|
|
|
System.out.println(client.queryForJSON(new QueryRequest()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void scanStatusByID() throws Exception {
|
2022-02-24 18:09:30 +01:00
|
|
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
2022-03-04 14:23:20 +01:00
|
|
|
Projects<M> client = (Projects<M>) getClient();
|
2022-02-04 17:45:47 +01:00
|
|
|
AtomicLong counter=new AtomicLong(0);
|
|
|
|
client.query(new QueryRequest()).forEachRemaining( m -> {
|
2022-02-23 17:13:22 +01:00
|
|
|
System.out.print(counter.incrementAndGet()+ ", ID : "+m.getId());
|
2022-02-04 17:45:47 +01:00
|
|
|
try {
|
2022-02-23 17:13:22 +01:00
|
|
|
M proj=client.getById(m.getId());
|
2022-02-04 17:45:47 +01:00
|
|
|
System.out.println("... OK.. STATUS : "+proj.getLifecycleInformation());
|
|
|
|
} catch (RemoteException e) {
|
2022-02-23 17:13:22 +01:00
|
|
|
System.err.println(" Error with "+m.getId());
|
2022-02-04 17:45:47 +01:00
|
|
|
System.err.println(e);
|
|
|
|
System.out.println("... ERRR !!!!");
|
|
|
|
}
|
|
|
|
});
|
2022-02-02 18:34:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|