Fixed test methods

This commit is contained in:
Fabio Sinibaldi 2021-09-21 17:45:18 +02:00
parent 6e15ea93cf
commit 7bc1cba00b
53 changed files with 212 additions and 122 deletions

View File

@ -0,0 +1,9 @@
package org.gcube.application.cms.tests;
public class ResourceScanner {
}

View File

@ -1,4 +1,4 @@
package org.gcube.application.cms.tests.model;
package org.gcube.application.cms.tests;
import lombok.extern.slf4j.Slf4j;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;

View File

@ -0,0 +1,37 @@
package org.gcube.application.cms.tests.model;
import org.gcube.application.geoportal.common.utils.Files;
import sun.misc.IOUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class TestFilters {
public static final HashMap<String,String> filters=new HashMap<>();
static{
for(File f:new File("../test-data/concessioni/filters").listFiles()){
try {
filters.put(f.getName(),new String(IOUtils.readAllBytes(new FileInputStream(f))));
} catch (IOException e) {
throw new RuntimeException("Unable to read "+f.getAbsolutePath(),e);
}
}
}
}

View File

@ -1,5 +1,6 @@
package org.gcube.application.cms.tests.model;
import java.io.File;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
@ -9,6 +10,14 @@ import org.gcube.application.geoportal.common.model.legacy.*;
public class TestModel {
public static File getBaseFolder(){
File toReturn =new File("../test-data/concessioni");
if(!toReturn.exists()) toReturn = new File("test-data/concessioni");
if(!toReturn.exists()) throw new RuntimeException("Unable to find test data");
return toReturn;
}
public static Concessione prepareEmptyConcessione() {
Concessione concessione=new Concessione();

View File

@ -0,0 +1,24 @@
package org.gcube.application.cms.tests.model;
import sun.misc.IOUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
public class TestQueries {
public static final HashMap<String,String> queries =new HashMap<>();
static{
for(File f:new File("../test-data/concessioni/queries").listFiles()){
try {
queries.put(f.getName(),new String(IOUtils.readAllBytes(new FileInputStream(f))));
} catch (IOException e) {
throw new RuntimeException("Unable to read "+f.getAbsolutePath(),e);
}
}
}
}

View File

@ -0,0 +1,25 @@
package org.gcube.application.cms.commons.model.concessioni;
import org.gcube.application.cms.tests.model.TestFilters;
import org.gcube.application.cms.tests.model.TestModel;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class Models {
@Test
public void checkFilters(){
assertTrue(TestFilters.filters.size()>0);
TestFilters.filters.keySet().forEach(f -> {
System.out.println(f);});
}
@Test
public void checkConcessione(){
Concessione c= TestModel.prepareConcessione(3,5);
assertTrue(c.getPianteFineScavo().size()==3);
assertTrue(c.getImmaginiRappresentative().size()==5);
}
}

View File

@ -35,7 +35,7 @@ public class SerializationTest {
public void readProfile() throws JsonProcessingException, IOException {
Profile concessione=mapper.readerFor(Profile.class).readValue(
Files.getFileFromResources("concessioni/ProfileConcessioni.json"));
Files.getFileFromResources("test-data/concessioni/ProfileConcessioni.json"));
System.out.println("Profile is "+mapper.writeValueAsString(concessione));
Assert.assertTrue(concessione.getFields().size()>0);
@ -45,7 +45,7 @@ public class SerializationTest {
@Test
public void readConcessione() throws JsonProcessingException, IOException {
Concessione concessione=mapper.readerFor(Concessione.class).readValue(
Files.getFileFromResources("concessioni/Concessione.json"));
Files.getFileFromResources("test-data/concessioni/Concessione.json"));
System.out.println("Concessione is "+concessione.toString());
}

View File

@ -1,23 +1,20 @@
package org.gcube.application.geoportal.client.legacy;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import javax.ws.rs.client.WebTarget;
import org.gcube.application.geoportal.client.DefaultMongoConcessioni;
import org.gcube.application.geoportal.client.utils.FileSets;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
import org.gcube.application.geoportal.common.model.legacy.InputStreamDescriptor;
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
public class StatefulMongoConcessioni extends DefaultMongoConcessioni implements ConcessioniManagerI{

View File

@ -13,9 +13,6 @@ import java.nio.charset.Charset;
public class Queries {
public static QueryRequest parse(String json) throws IOException {
Document queryDocument=Document.parse(json);
QueryRequest req=new QueryRequest();

View File

@ -1,33 +1,43 @@
package org.gcube.application.geoportal;
import org.gcube.application.cms.tests.model.TokenSetter;
import org.apache.commons.io.IOUtils;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.cms.tests.model.TestModel;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.utils.Files;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class StorageTests {
public static void main(String[] args) throws FileNotFoundException {
FileInputStream fis =new FileInputStream(Files.getFileFromResources("concessioni/relazione.pdf"));
public static void main(String[] args) throws IOException {
String filename= "relazione.pdf";
String sourceContext="/d4science.research-infrastructures.eu";
String targetContext="/pred4s/preprod/preVRE";
// String sourceContext="/d4science.research-infrastructures.eu";
// String targetContext="/pred4s/preprod/preVRE";
String targetContext="/gcube/devsec/devVRE";
TokenSetter.set(sourceContext);
StorageHubClient sgClient=new StorageHubClient();
// TokenSetter.set(sourceContext);
// StorageHubClient sgClient=new StorageHubClient();
// System.out.println(new StorageUtils().getUrlById(file.getId()));
TokenSetter.set(targetContext);
TempFile file= new StorageUtils().putOntoStorage(fis,filename);
System.out.println(new File(".").getAbsolutePath());
TempFile file= new StorageUtils().putOntoStorage(new File(TestModel.getBaseFolder(),filename),filename);
IOUtils.copy(new URL(StorageUtils.getUrlById(file.getId())).openStream(),System.out);
System.out.println(new StorageUtils().getUrlById(file.getId()));
}

View File

@ -1,6 +1,6 @@
package org.gcube.application.geoportal.clients;
import org.gcube.application.cms.tests.model.TokenSetter;
import org.gcube.application.cms.tests.TokenSetter;
import org.junit.BeforeClass;
public class BasicVreTests {

View File

@ -37,28 +37,28 @@ public class StatefulClientTests extends BasicVreTests{
UploadedImage toRegisterImg= TestModel.prepareConcessione().getImmaginiRappresentative().get(0);
// TEMP Files are hosted in INFRASTRUCTURE's VOLATILE AREA
TempFile toUpload=storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("concessioni/immagine.png")), "immagine.png");
TempFile toUpload=storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("test-data/concessioni/immagine.png")), "immagine.png");
manager.addImmagineRappresentativa(toRegisterImg, toUpload);
//Alternative Method
InputStreamDescriptor isDesc=new InputStreamDescriptor(new FileInputStream(Files.getFileFromResources("concessioni/immagine.png")), "immagine.png");
InputStreamDescriptor isDesc=new InputStreamDescriptor(new FileInputStream(Files.getFileFromResources("test-data/concessioni/immagine.png")), "immagine.png");
manager.addImmagineRappresentativa(toRegisterImg, isDesc);
//Relazione
manager.setRelazioneScavo(TestModel.prepareConcessione().getRelazioneScavo(),
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("concessioni/relazione.pdf")), "relazione_it.pdf"),
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("concessioni/relazione.pdf")), "relazione_en.pdf"));
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("test-data/concessioni/relazione.pdf")), "relazione_it.pdf"),
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("test-data/concessioni/relazione.pdf")), "relazione_en.pdf"));
// Posizionamento scavo
manager.setPosizionamento(TestModel.prepareConcessione().getPosizionamentoScavo(),
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("concessioni/pos.shp")), "pos.shp"));
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("test-data/concessioni/pos.shp")), "pos.shp"));
// Piante
manager.addPiantaFineScavo(TestModel.prepareConcessione().getPianteFineScavo().get(0),
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("concessioni/pianta.shp")), "pianta.shp"),
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("concessioni/pianta.shx")), "pianta.shx"));
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("test-data/concessioni/pianta.shp")), "pianta.shp"),
storage.putOntoStorage(new FileInputStream(Files.getFileFromResources("test-data/concessioni/pianta.shx")), "pianta.shx"));
return manager.publish();
}

View File

@ -10,13 +10,16 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicLong;
import org.gcube.application.cms.tests.model.TestFilters;
import org.gcube.application.cms.tests.model.TestModel;
import org.gcube.application.cms.tests.model.TestQueries;
import org.gcube.application.geoportal.client.utils.Queries;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.utils.Files;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.junit.Test;
@ -64,7 +67,7 @@ public class StatelessClientTests extends BasicVreTests{
AddSectionToConcessioneRequest request=
new AddSectionToConcessioneRequest(Paths.RELAZIONE,
Collections.singletonList(new StorageUtils().putOntoStorage(
new FileInputStream(Files.getFileFromResources("concessioni/relazione.pdf")), "relazione.pdf")));
new FileInputStream(Files.getFileFromResources("test-data/concessioni/relazione.pdf")), "relazione.pdf")));
c= client.registerFileSet(c.getMongo_id(), request);
@ -86,37 +89,21 @@ public class StatelessClientTests extends BasicVreTests{
public static Concessione publish(Boolean verify,MongoConcessioni client) throws Exception {
Concessione c= client.createNew(TestModel.prepareConcessione());
StorageUtils storage = new StorageUtils();
String mongoId=c.getMongo_id();
AddSectionToConcessioneRequest request=
new AddSectionToConcessioneRequest(Paths.RELAZIONE,
Collections.singletonList(new StorageUtils().putOntoStorage(
new FileInputStream(Files.getFileFromResources("concessioni/relazione.pdf")), "relazione.pdf")));
client.registerFileSet(mongoId,
FileSets.prepareRequest(storage,Paths.RELAZIONE,new File(TestModel.getBaseFolder(),"relazione.pdf")));
client.registerFileSet(mongoId, request);
client.registerFileSet(mongoId,
FileSets.prepareRequest(storage,Paths.imgByIndex(0),new File(TestModel.getBaseFolder(),"immagine.pdf")));
request=
new AddSectionToConcessioneRequest(Paths.imgByIndex(0),
Collections.singletonList(new StorageUtils().putOntoStorage(
new FileInputStream(Files.getFileFromResources("concessioni/immagine.png")), "immagine.png")));
client.registerFileSet(mongoId,
FileSets.prepareRequest(storage,Paths.POSIZIONAMENTO,new File(TestModel.getBaseFolder(),"pos.shp")));
client.registerFileSet(mongoId, request);
request=
new AddSectionToConcessioneRequest(Paths.POSIZIONAMENTO,
Collections.singletonList(new StorageUtils().putOntoStorage(
new FileInputStream(Files.getFileFromResources("concessioni/pos.shp")), "pos.shp")));
client.registerFileSet(mongoId, request);
request=
new AddSectionToConcessioneRequest(Paths.piantaByIndex(0),
Collections.singletonList(new StorageUtils().putOntoStorage(
new FileInputStream(Files.getFileFromResources("concessioni/pianta.shp")), "pianta.shp")));
client.registerFileSet(mongoId, request);
client.registerFileSet(mongoId,
FileSets.prepareRequest(storage,Paths.piantaByIndex(0),new File(TestModel.getBaseFolder(),"pianta.shp")));
c=client.publish(mongoId);
@ -135,10 +122,13 @@ public class StatelessClientTests extends BasicVreTests{
@Test
public void searches() throws Exception {
for(File filterFile:new File("src/test/resources/concessioni/filters").listFiles()) {
String query=Files.readFileAsString(filterFile.getAbsolutePath(), Charset.defaultCharset());
System.out.println("Count for "+filterFile.getName()+"\t"+ count(client.search(query)));
}
TestFilters.filters.forEach((k,v)->{
try {
System.out.println("Count for " + k + "\t" + count(client.search(v)));
}catch (Exception e){
throw new RuntimeException(e);
}
});
}
@ -147,7 +137,7 @@ public class StatelessClientTests extends BasicVreTests{
// No Transformation
System.out.print("First Registered \t");
Iterator<Concessione> queriedDocuments=client.query(
Queries.readPath("src/test/resources/concessioni/queries/firstRegistered.json"));
Queries.parse(TestQueries.queries.get("firstRegistered.json")));
// Expected one result
assertTrue(count(queriedDocuments)==1);
@ -156,7 +146,7 @@ public class StatelessClientTests extends BasicVreTests{
System.out.print("Last Registered \t");
// Expected one result
queriedDocuments=client.query(
Queries.readPath("src/test/resources/concessioni/queries/lastRegistered.json"));
Queries.parse(TestQueries.queries.get("lastRegistered.json")));
assertTrue(count(queriedDocuments)==1);
queriedDocuments.forEachRemaining((Concessione c)->{System.out.println(c.getNome());});
@ -165,16 +155,11 @@ public class StatelessClientTests extends BasicVreTests{
// Transformations
System.out.println(
client.queryForJSON(
Queries.readPath("src/test/resources/concessioni/queries/lastNameRegisteredByFabio.json")));
Queries.parse(TestQueries.queries.get("lastNameRegisteredByFabio.json"))));
System.out.println(
client.queryForJSON(
Queries.readPath("src/test/resources/concessioni/queries/publicationWarningMessages.json")));
Queries.parse(TestQueries.queries.get("publicationWarningMessages.json"))));
// String query=Files.readFileAsString(filterFile.getAbsolutePath(), Charset.defaultCharset());
// System.out.println("Count for "+filterFile.getName()+"\t"+ count(client.search(query)));

View File

@ -18,7 +18,7 @@ public class ConcessioniTests extends BasicVreTests {
@Test
// NB LEGACY
public void readAll() throws Exception {
ConcessioniManager manager=new ConcessioniManager();
ArrayList<Concessione> found=manager.getList();

View File

@ -1,6 +1,6 @@
package org.gcube.application.geoportal.usecases;
import org.gcube.application.cms.tests.model.TokenSetter;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI;
import org.gcube.application.geoportal.common.model.legacy.Concessione;

View File

@ -1,7 +1,7 @@
package org.gcube.application.geoportal.usecases;
import org.gcube.application.cms.tests.model.TokenSetter;
import org.gcube.application.geoportal.client.utils.FileSets;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.model.legacy.Concessione;

View File

@ -1,7 +1,7 @@
package org.gcube.application.geoportal.usecases;
import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.tests.model.TokenSetter;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI;
import org.gcube.application.geoportal.client.utils.Serialization;

View File

@ -2,7 +2,7 @@ package org.gcube.application.geoportal.usecases;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.gcube.application.cms.tests.model.TokenSetter;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.client.legacy.ConcessioniManager;
import org.gcube.application.geoportal.client.utils.Serialization;

View File

@ -1,6 +1,6 @@
package org.gcube.application.geoportal.usecases;
import org.gcube.application.cms.tests.model.TokenSetter;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI;
import org.gcube.application.geoportal.common.model.legacy.Concessione;

View File

@ -1,6 +1,6 @@
package org.gcube.application.geoportal.usecases;
import org.gcube.application.cms.tests.model.TokenSetter;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI;

View File

@ -3,8 +3,8 @@ package org.gcube.application.geoportal.usecases.mocks;
import com.opencsv.CSVReader;
import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.tests.model.TestModel;
import org.gcube.application.cms.tests.model.TokenSetter;
import org.gcube.application.geoportal.client.utils.FileSets;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;

View File

@ -1,17 +1,14 @@
package org.gcube.application.geoportal.client.utils;
package org.gcube.application.geoportal.common.utils;
import org.gcube.application.geoportal.common.model.legacy.InputStreamDescriptor;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class FileSets {

View File

@ -1,5 +1,7 @@
package org.gcube.application.geoportal.common.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.UUID;
@ -26,13 +28,24 @@ public class StorageUtils {
client=getClient();
}
//return Id
public TempFile putOntoStorage(InputStream source,String filename) throws RemoteBackendException, FileNotFoundException{
log.debug("Uploading source "+filename);
String id=client.put(true).LFile(source).RFile(getUniqueString());
return new TempFile(id,filename);
}
public TempFile putOntoStorage(File source, String filename) throws RemoteBackendException, FileNotFoundException{
if(source.exists() && source.canRead())
return putOntoStorage(new FileInputStream(source),filename);
else throw new FileNotFoundException("Unable to read "+filename);
}
public TempFile putOntoStorage(String sourcePath, String filename) throws RemoteBackendException, FileNotFoundException{
return putOntoStorage(new File(sourcePath),filename);
}
public static final boolean checkStorageId(String id){
return getClient().getHttpUrl().RFile(id)!=null;
}

View File

@ -1,14 +1,14 @@
package org.gcube.application.geoportal.service;
import org.gcube.application.cms.tests.model.TestFilters;
import org.gcube.application.cms.tests.model.TestQueries;
import org.gcube.application.cms.tests.model.TestModel;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.utils.Files;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.application.geoportal.service.utils.Serialization;
import org.json.JSONObject;
@ -20,9 +20,7 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.FileInputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
@ -43,21 +41,15 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{
}
private static Concessione upload(WebTarget target,String id, String path, String ...files) throws Exception {
private static Concessione upload(StorageUtils storage, WebTarget target,String id, String path, String ...files) throws Exception {
FileSets.RequestBuilder builder = FileSets.build(path);
ArrayList<TempFile> array=new ArrayList<TempFile>();
for(String file:files)
array.add(new StorageUtils().putOntoStorage(new FileInputStream(
Files.getFileFromResources("concessioni/"+file)), file));
AddSectionToConcessioneRequest request=new AddSectionToConcessioneRequest();
request.setDestinationPath(path);
request.setStreams(array);
return check(target.path(FILES_PATH).path(id).request(MediaType.APPLICATION_JSON).post(Entity.entity(Serialization.write(request), MediaType.APPLICATION_JSON)),Concessione.class);
builder.add(storage.putOntoStorage(new File(TestModel.getBaseFolder(),file),file));
return check(target.path(FILES_PATH).path(id).request(MediaType.APPLICATION_JSON).
post(Entity.entity(Serialization.write(builder.getTheRequest()),
MediaType.APPLICATION_JSON)),Concessione.class);
}
@ -92,15 +84,10 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{
return Serialization.readCollection(result,Concessione.class);
}
private static Iterator<Concessione> searchFile(String filename, WebTarget target) throws Exception {
String query= Files.readFileAsString(Files.getFileFromResources(
"concessioni/jsonFilters/"+filename).getAbsolutePath(), Charset.defaultCharset());
return search(query,target);
}
private static <T> Iterator<T> queryFile(String filename, WebTarget target, Class<T> clazz) throws Exception {
String queryString= Files.readFileAsString(Files.getFileFromResources(
"concessioni/jsonQueries/"+filename).getAbsolutePath(), Charset.defaultCharset());
String queryString= TestQueries.queries.get(filename);
String result = check(target.path(InterfaceConstants.Methods.QUERY_PATH).request(MediaType.APPLICATION_JSON_TYPE).post(
Entity.entity(queryString,MediaType.APPLICATION_JSON)),String.class);
@ -123,7 +110,7 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{
public void search() throws Exception {
WebTarget target=target(PATH);
AtomicLong validatedCount= new AtomicLong(0);
Iterator<Concessione> it=searchFile("validated.json",target);
Iterator<Concessione> it=search(TestFilters.filters.get("validated.json"),target);
it.forEachRemaining(concessione -> {validatedCount.incrementAndGet();});
System.out.println("Validated : "+ validatedCount.get());
}
@ -141,7 +128,7 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{
assertTrue(count(it)==1);
System.out.println("Last Names by Fabio : ");
queryFile("lastNamesRegisteredByFabio.json", target, JSONObject.class).forEachRemaining(c -> {System.out.println(c);});
queryFile("lastNameRegisteredByFabio.json", target, JSONObject.class).forEachRemaining(c -> {System.out.println(c);});
System.out.println("Publication warning messages : ");
queryFile("publicationWarningMessages.json", target, JSONObject.class).forEachRemaining(c -> {System.out.println(c);});
@ -236,7 +223,7 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{
c=upload(target,c.getMongo_id(),Paths.RELAZIONE,"relazione.pdf");
c=upload(new StorageUtils(),target,c.getMongo_id(),Paths.RELAZIONE,"relazione.pdf");
assertNotNull(c.getRelazioneScavo().getActualContent());
assertTrue(c.getRelazioneScavo().getActualContent().size()>0);
@ -298,20 +285,20 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{
Concessione c=TestModel.prepareConcessione(1,2);
c.setNome("Concessione : publish test");
StorageUtils storage=new StorageUtils();
// Register new
c=register(target,c);
//Upload files
upload(target,c.getMongo_id(),Paths.RELAZIONE,"relazione.pdf");
upload(target,c.getMongo_id(),Paths.POSIZIONAMENTO,"pos.shp","pos.shx");
upload(storage,target,c.getMongo_id(),Paths.RELAZIONE,"relazione.pdf");
upload(storage,target,c.getMongo_id(),Paths.POSIZIONAMENTO,"pos.shp","pos.shx");
// Clash on workspaces
upload(target,c.getMongo_id(),Paths.piantaByIndex(0),"pianta.shp","pianta.shx");
upload(target,c.getMongo_id(),Paths.imgByIndex(0),"immagine.png");
upload(target,c.getMongo_id(),Paths.imgByIndex(1),"immagine2.png");
upload(storage,target,c.getMongo_id(),Paths.piantaByIndex(0),"pianta.shp","pianta.shx");
upload(storage,target,c.getMongo_id(),Paths.imgByIndex(0),"immagine.png");
upload(storage,target,c.getMongo_id(),Paths.imgByIndex(1),"immagine2.png");

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB