2021-09-20 16:47:35 +02:00
|
|
|
package org.gcube.application.geoportal.service;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.mongodb.Block;
|
|
|
|
import com.mongodb.MongoClient;
|
|
|
|
import com.mongodb.client.MongoCollection;
|
|
|
|
import com.mongodb.client.MongoDatabase;
|
|
|
|
import com.mongodb.client.model.Projections;
|
|
|
|
import org.bson.Document;
|
2021-10-01 17:42:23 +02:00
|
|
|
import org.gcube.application.cms.tests.TokenSetter;
|
2021-09-20 16:47:35 +02:00
|
|
|
import org.gcube.application.geoportal.service.engine.ImplementationProvider;
|
|
|
|
import org.gcube.application.geoportal.service.engine.mongo.MongoManager;
|
|
|
|
import org.gcube.application.geoportal.service.engine.providers.MongoClientProvider;
|
2021-10-14 17:00:08 +02:00
|
|
|
import org.gcube.application.geoportal.service.model.internal.db.Mongo;
|
2021-09-20 16:47:35 +02:00
|
|
|
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class MongoTests {
|
|
|
|
|
|
|
|
public static class MongoTester extends MongoManager {
|
|
|
|
|
|
|
|
public MongoTester() throws ConfigurationException {
|
|
|
|
}
|
|
|
|
|
|
|
|
public MongoCollection<Document> getCollection(){return getDatabase().getCollection("legacyConcessioni");}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected MongoDatabase getDatabase() {
|
2021-10-14 17:00:08 +02:00
|
|
|
return client.getTheClient().getDatabase("gna_dev");
|
2021-09-20 16:47:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static final void init() {
|
|
|
|
ImplementationProvider.get().setMongoClientProvider(new MongoClientProvider() {
|
|
|
|
@Override
|
2021-10-14 17:00:08 +02:00
|
|
|
public Mongo getObject() throws ConfigurationException {
|
2021-09-20 16:47:35 +02:00
|
|
|
TokenSetter.set("/gcube/devsec/devVRE");
|
|
|
|
return super.getObject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Block<Document> printBlock = new Block<Document>() {
|
|
|
|
@Override
|
|
|
|
public void apply(final Document document) {
|
|
|
|
System.out.println(document.toJson());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void listProfiles() throws JsonProcessingException, IOException, ConfigurationException {
|
|
|
|
// MongoManager manager=new MongoManager();
|
|
|
|
// Profile f=Serialization.mapper.readerFor(Profile.class).readValue(
|
|
|
|
// Files.getFileFromResources("fakeProfile.json"));
|
|
|
|
//
|
|
|
|
// manager.iterate(new Document(),f).forEach(printBlock);
|
|
|
|
}
|
|
|
|
|
2021-10-06 11:26:35 +02:00
|
|
|
@Test
|
|
|
|
public void bruteForce(){
|
|
|
|
|
|
|
|
}
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void queries() throws ConfigurationException {
|
|
|
|
MongoTester tester=new MongoTester();
|
|
|
|
System.out.println("Using builders..");
|
|
|
|
tester.getCollection().find(Document.parse("{\"report.status\" : \"WARNING\"}")).
|
|
|
|
projection(Projections.include("nome")).forEach(printBlock);
|
|
|
|
System.out.println("Deserializing documents");
|
|
|
|
tester.getCollection().find(Document.parse("{\"report.status\" : \"WARNING\"}")).
|
|
|
|
projection(Document.parse("{\"nome\" : 1}")).forEach(printBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkQuerySerialization(){
|
|
|
|
System.out.println(Projections.include("nome"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
// public void writeProject() {
|
|
|
|
// MongoManager manager=new MongoManager();
|
|
|
|
// Concessione f=Serialization.mapper.readerFor(Concessione.class).readValue(
|
|
|
|
// Files.getFileFromResources("fakeProfile.json"));
|
|
|
|
// }
|
|
|
|
}
|