From a1c0913e41e4896997e2729875edb62103845700 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Mon, 26 Sep 2022 16:22:25 +0200 Subject: [PATCH] Import cleanup --- .../clients/legacy/ConcessioniTests.java | 81 ----- .../clients/legacy/StatefulClientTests.java | 135 -------- .../clients/legacy/StatelessClientTests.java | 301 ------------------ .../mocks/ConcessionPublisherThread.java | 72 ++--- 4 files changed, 36 insertions(+), 553 deletions(-) delete mode 100644 geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/ConcessioniTests.java delete mode 100644 geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/StatefulClientTests.java delete mode 100644 geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/StatelessClientTests.java diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/ConcessioniTests.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/ConcessioniTests.java deleted file mode 100644 index dd79a64..0000000 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/ConcessioniTests.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.gcube.application.geoportal.clients.legacy; - -import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicLong; - -import org.gcube.application.geoportal.client.legacy.ConcessioniManager; -import org.gcube.application.geoportal.clients.BasicVreTests; -import org.gcube.application.geoportal.common.model.legacy.Concessione; -import org.gcube.application.geoportal.common.model.legacy.GeoServerContent; -import org.gcube.application.geoportal.common.model.legacy.LayerConcessione; -import org.gcube.application.geoportal.common.model.legacy.PersistedContent; -import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus; -import org.junit.Test; - -public class ConcessioniTests extends BasicVreTests { - - static boolean STOP_ON_FAIL=true; - - - - // NB LEGACY - public void readAll() throws Exception { - ConcessioniManager manager=new ConcessioniManager(); - ArrayList found=manager.getList(); - System.out.println("Found "+found.size()+" elements."); - final AtomicLong byId=new AtomicLong(0); - - final ArrayList validIDs=new ArrayList<>(); - - final ArrayList imgs=new ArrayList(); - final AtomicLong error=new AtomicLong(0); - - final ArrayList piante=new ArrayList(); - final ArrayList pos=new ArrayList(); - final ArrayList wmsLink=new ArrayList(); - - found.forEach((Concessione c )->{ - try { - manager.getById(c.getId()+""); - byId.incrementAndGet(); - if(c.validate().getStatus().equals(ValidationStatus.PASSED)) - validIDs.add(c.getId()); - if(c.getImmaginiRappresentative()!=null&&c.getImmaginiRappresentative().size()>0) - imgs.add(c.getId()); - if(c.getPianteFineScavo()!=null) - c.getPianteFineScavo().forEach((LayerConcessione l)->{ - if(l.getActualContent()!=null) - l.getActualContent().forEach((PersistedContent p)->{ - if(p instanceof GeoServerContent) piante.add(c.getId()); - }); - if(l.getWmsLink()!=null) wmsLink.add(c.getId()); - }); - - if(c.getPosizionamentoScavo()!=null) { - LayerConcessione l=c.getPosizionamentoScavo(); - l.getActualContent().forEach((PersistedContent p)->{ - if(p instanceof GeoServerContent) pos.add(c.getId()); - }); - if(l.getWmsLink()!=null) wmsLink.add(c.getId()); - } - }catch(Throwable t) { - error.incrementAndGet(); - if(STOP_ON_FAIL) { - throw new RuntimeException(t); - }else t.printStackTrace(System.err); - } - }); - System.out.println("Valid count "+validIDs.size()+ "Load BY ID : "+byId.get()+" Error : "+error.get()+" OUT OF "+found.size()); - System.out.println("Valid IDS "+validIDs); - System.out.println("With imgs : "+imgs); - System.out.println("With piante : "+piante); - System.out.println("With pos : "+pos); - System.out.println("With wmsLink : "+wmsLink); - } - - - - - - -} diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/StatefulClientTests.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/StatefulClientTests.java deleted file mode 100644 index 8c8dcb3..0000000 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/StatefulClientTests.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.gcube.application.geoportal.clients.legacy; - -import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.statefulMongoConcessioni; -import static org.junit.Assert.*; -import static org.junit.Assume.assumeTrue; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; - - -import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel; -import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI; -import org.gcube.application.geoportal.client.utils.Serialization; -import org.gcube.application.geoportal.clients.BasicVreTests; -import org.gcube.application.geoportal.common.model.legacy.*; -import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus; -import org.gcube.application.geoportal.common.model.rest.TempFile; -import org.gcube.application.geoportal.common.utils.StorageUtils; -import org.gcube.application.geoportal.common.utils.tests.GCubeTest; -import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException; -import org.junit.Test; - - -public class StatefulClientTests extends BasicVreTests { - - - - private Concessione publishNew() throws Exception { - ConcessioniManagerI manager=statefulMongoConcessioni().build(); - StorageUtils storage=new StorageUtils(); - - - Concessione toRegister= TestConcessioniModel.prepareEmptyConcessione(); - toRegister.setNome("Mock module"); - manager.createNew(toRegister); - - - - - Concessione source=TestConcessioniModel.prepareConcessione(); - - - - for(UploadedImage toRegisterImg : source.getImmaginiRappresentative()){ - - // TEMP Files are hosted in INFRASTRUCTURE's VOLATILE AREA - TempFile toUpload=storage.putOntoStorage( - new File(TestConcessioniModel.getBaseFolder(),"immagine1.png"), "immagine.png"); - - manager.addImmagineRappresentativa(toRegisterImg, toUpload); - } - - - -// //Alternative Method -// InputStreamDescriptor isDesc= -// new InputStreamDescriptor(new FileInputStream(new File(TestConcessioniModel.getBaseFolder(), -// "immagine1.png")), "San Mauro_drone totale.JPG"); -// manager.addImmagineRappresentativa(toRegisterImg, isDesc); - - source.getRelazioneScavo().setPolicy(AccessPolicy.EMBARGOED); - assertEquals(AccessPolicy.EMBARGOED,source.getRelazioneScavo().getPolicy()); - - //Relazione - manager.setRelazioneScavo(source.getRelazioneScavo(), - storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"), "relazione_it.pdf"), - storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"), "relazione_en.pdf")); - assertEquals(AccessPolicy.EMBARGOED,manager.getCurrent().getRelazioneScavo().getPolicy()); - - //Abstract - manager.setAbstractRelazioneScavo( - source.getAbstractRelazione(), - storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"), "abstract.pdf"), - storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"), "abstract.pdf")); - - - - // Posizionamento scavo - - manager.setPosizionamento(source.getPosizionamentoScavo(), - storage.putOntoStorage( - new File(TestConcessioniModel.getBaseFolder(),"pos.shp"),"pos.shp")); - - // Piante - manager.addPiantaFineScavo(source.getPianteFineScavo().get(0), - storage.putOntoStorage( - new File(TestConcessioniModel.getBaseFolder(),"pianta.shp"),"pianta.shp")); -// new File("/Users/fabioisti/Documents/invio_08_05/Montalto di Castro (VT)_Vulci_Indagini non invasive_Doc. paragr._Va/CONSEGNA_WGS84") -// .listFiles((file,name)->{return name.startsWith("Mag_anomalies_WGS84");}))); - - - - Concessione toReturn=manager.publish(); - assertEquals(AccessPolicy.EMBARGOED,toReturn.getRelazioneScavo().getPolicy()); - return toReturn; - } - - - - @Test - public void testRegisterNew() throws RemoteBackendException, FileNotFoundException, Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - Concessione published=publishNew(); - - - // VARIOUS CHECKS - assertNotNull(published.getReport()); - assertEquals(published.getReport().getStatus(),ValidationStatus.PASSED); - - assertEquals(published.getImmaginiRappresentative().size(),2); - assertEquals(published.getPianteFineScavo().size(),1); - assertNotNull(published.getPosizionamentoScavo().getWmsLink()); - for(LayerConcessione l : published.getPianteFineScavo()) - assertNotNull(l.getWmsLink()); - assertNotNull(published.getCentroidLat()); - assertNotNull(published.getCentroidLong()); - - System.out.println(Serialization.write(published)); - System.out.println(Serialization.write(published.getReport())); - } - - @Test - public void delete() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - ConcessioniManagerI manager=statefulMongoConcessioni().build(); - StorageUtils storage=new StorageUtils(); - - manager.createNew(TestConcessioniModel.prepareEmptyConcessione()); - - manager.delete(); - } - - -} diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/StatelessClientTests.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/StatelessClientTests.java deleted file mode 100644 index a230674..0000000 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/legacy/StatelessClientTests.java +++ /dev/null @@ -1,301 +0,0 @@ -package org.gcube.application.geoportal.clients.legacy; - -import org.gcube.application.cms.tests.model.concessioni.TestConcessioniFilters; -import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel; -import org.gcube.application.cms.tests.model.concessioni.TestConcessioniQueries; -import org.gcube.application.geoportal.client.utils.ConcessioniUtils; -import org.gcube.application.geoportal.client.utils.Queries; -import org.gcube.application.geoportal.client.utils.Serialization; -import org.gcube.application.geoportal.clients.BasicVreTests; -import org.gcube.application.geoportal.common.model.legacy.*; -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.StorageUtils; -import org.gcube.application.geoportal.common.utils.tests.GCubeTest; -import org.junit.Test; - -import java.io.File; -import java.util.Iterator; -import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Collectors; - -import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.mongoConcessioni; -import static org.junit.Assert.*; -import static org.junit.Assume.assumeTrue; - -public class StatelessClientTests extends BasicVreTests { - - - private final MongoConcessioni client=mongoConcessioni().build(); - - @Test - public void getConfiguration() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - System.out.println(client.getCurrentConfiguration()); - } - - @Test - public void searches() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - TestConcessioniFilters.filters.forEach((k, v)->{ - try { - System.out.println("Count for " + k + "\t" + count(client.search(v))); - }catch (Exception e){ - throw new RuntimeException(e); - } - }); - - - } - - - @Test - public void query() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - System.out.println("FRA "+ count(client.query( - Queries.parse(TestConcessioniQueries.queries.get("emptyresult.json"))))); - - // No Transformation - System.out.print("First Registered \t"); - Iterator queriedDocuments=client.query( - Queries.parse(TestConcessioniQueries.queries.get("firstRegistered.json"))); - // Expected one result - assertTrue(count(queriedDocuments)==1); - - - - System.out.print("Last Registered \t"); - // Expected one result - queriedDocuments=client.query( - Queries.parse(TestConcessioniQueries.queries.get("lastRegistered.json"))); - assertTrue(count(queriedDocuments)==1); - - queriedDocuments.forEachRemaining((Concessione c)->{System.out.println(c.getNome());}); - - - // Transformations - System.out.println( - client.queryForJSON( - Queries.parse(TestConcessioniQueries.queries.get("lastNameRegisteredByFabio.json")))); - - System.out.println( - client.queryForJSON( - Queries.parse(TestConcessioniQueries.queries.get("publicationWarningMessages.json")))); - -// String query=Files.readFileAsString(filterFile.getAbsolutePath(), Charset.defaultCharset()); -// System.out.println("Count for "+filterFile.getName()+"\t"+ count(client.search(query))); -// } - } - - @Test - public void testList() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - final AtomicLong counter=new AtomicLong(); - long before=System.currentTimeMillis(); - client.getList().forEachRemaining((Concessione c)-> {counter.addAndGet(1);}); - System.out.println("Loaded "+counter+" in "+(System.currentTimeMillis()-before)+" ms"); - } - - @Test - public void testCreateNew() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - Concessione c= client.createNew(TestConcessioniModel.prepareEmptyConcessione()); - assertNotNull(c); - assertNotNull(c.getMongo_id()); - } - - - - @Test - public void testClone() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - //Concessione c= prepare(); - Concessione c = client.getById("6165af0102ad3d60e1d26edd"); - Concessione copied = ConcessioniUtils.clone(client,c.getMongo_id()); - assertEquals(copied.getNome(),c.getNome()); - checkCopied(copied.getRelazioneScavo(),c.getRelazioneScavo()); - checkCopied(copied.getAbstractRelazione(),c.getAbstractRelazione()); - checkCopied(copied.getPosizionamentoScavo(),c.getPosizionamentoScavo()); - assertEquals(copied.getPianteFineScavo().size(),c.getPianteFineScavo().size()); - for(int i=0;i persistedContent instanceof WorkspaceContent). - collect(Collectors.toList()).size(); - - assertEquals(copied.getActualContent().size(),oriringalCount); - } - } - - - - @Test - public void testReplace() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - Concessione testObject= client.createNew(TestConcessioniModel.prepareEmptyConcessione()); - String title="My new shiny Title"; - testObject.setNome(title); - Concessione c1=client.replace(testObject); - assertEquals(title, c1.getNome()); - } - - @Test - public void testUploadFileSet() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - Concessione testObject= client.createNew(TestConcessioniModel.prepareConcessione()); - AddSectionToConcessioneRequest request= - Serialization.convert( -// FileSets.prepareRequest(new StorageUtils(),Paths.RELAZIONE,new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf")); - FileSets.build(Paths.ABSTRACT_RELAZIONE,null,null).add( - new StorageUtils().putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"),"San Mauro_drone totale.JPG")) - .getTheRequest(),AddSectionToConcessioneRequest.class); - - testObject= client.registerFileSet(testObject.getMongo_id(), request); - - assertNotNull(testObject.getContentByPath(Paths.ABSTRACT_RELAZIONE).getActualContent()); - assertNotNull(testObject.getContentByPath(Paths.ABSTRACT_RELAZIONE).getActualContent().get(0)); - } - - - - @Test - public void testDeleteById() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - Concessione c= client.createNew(TestConcessioniModel.prepareEmptyConcessione()); - client.deleteById(c.getMongo_id()); - } - - - @Test - public void testPublish() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - Concessione c=prepare(); - - assertTrue(c.getReport().getStatus().equals(ValidationStatus.PASSED)); - - - } - - @Test - public void testCleanFileSet() throws Exception { - assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - Concessione testObject=prepare(); - System.out.println("Object is "+testObject.getPosizionamentoScavo()); - //Precheck to be sure - assertFalse(testObject.getPosizionamentoScavo().getActualContent().isEmpty()); - assertFalse(testObject.getPianteFineScavo().get(0).getActualContent().isEmpty()); - - client.unPublish(testObject.getMongo_id()); - - // check unpublish - testObject= client.getById(testObject.getMongo_id()); - for(LayerConcessione l:testObject.getPianteFineScavo()) - for(PersistedContent pc: l.getActualContent()) - if(pc instanceof GeoServerContent) throw new Exception ("Concessione not properly unpublished"); - - for(PersistedContent pc: testObject.getPosizionamentoScavo().getActualContent()) - if(pc instanceof GeoServerContent) throw new Exception ("Concessione not properly unpublished"); - - - //Clear pos - testObject=client.cleanFileSet(testObject.getMongo_id(),Paths.POSIZIONAMENTO); - assertTrue(testObject.getPosizionamentoScavo().getActualContent().isEmpty()); - - //Clear pianta [0] - testObject =client.cleanFileSet(testObject.getMongo_id(),Paths.piantaByIndex(0)); - assertTrue(testObject.getPianteFineScavo().get(0).getActualContent().isEmpty()); - } - - - private Concessione prepare() throws Exception { - int numImgs=1; - Concessione c= client.createNew(TestConcessioniModel.prepareConcessione(1,numImgs)); - StorageUtils storage = new StorageUtils(); - - c.getRelazioneScavo().setPolicy(AccessPolicy.EMBARGOED); - String mongoId=c.getMongo_id(); - c=client.update(mongoId, Serialization.write(c)); - - assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); - - c=client.registerFileSet(mongoId, - Serialization.convert(FileSets.prepareRequest(storage,Paths.RELAZIONE,null,null, - new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf")), AddSectionToConcessioneRequest.class)); - - assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); - - c=client.registerFileSet(mongoId, - Serialization.convert( - FileSets.prepareRequest(storage,Paths.ABSTRACT_RELAZIONE,null, null, new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf")),AddSectionToConcessioneRequest.class)); - - assertEquals(AccessPolicy.EMBARGOED,c.getRelazioneScavo().getPolicy()); - - for(int i=0;i iterator){ - AtomicLong l=new AtomicLong(0); - iterator.forEachRemaining(el->{l.incrementAndGet();}); - return l.get(); - } - - -} diff --git a/use-cases/src/test/java/org/gcube/application/cms/usecases/mocks/ConcessionPublisherThread.java b/use-cases/src/test/java/org/gcube/application/cms/usecases/mocks/ConcessionPublisherThread.java index ca3844f..4e95d55 100644 --- a/use-cases/src/test/java/org/gcube/application/cms/usecases/mocks/ConcessionPublisherThread.java +++ b/use-cases/src/test/java/org/gcube/application/cms/usecases/mocks/ConcessionPublisherThread.java @@ -5,8 +5,6 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.ToString; import lombok.extern.slf4j.Slf4j; -import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel; -import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.model.legacy.InputStreamDescriptor; import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest; @@ -137,40 +135,42 @@ public class ConcessionPublisherThread implements Runnable{ private static Concessione createMock(String baseName, String packageName, Map> piante, List pos, MongoConcessioni client, StorageUtils storage) throws Exception { - Concessione c= TestConcessioniModel.prepareConcessione(piante.size(), 1); - c.setNome("Mock for "+baseName+" ("+packageName+")"); - c= client.createNew(c); - String mongoId=c.getMongo_id(); + return null; - // TEST DATA, DO NOT CARE - client.registerFileSet(mongoId, prepareRequest(storage, - Concessione.Paths.RELAZIONE,new File (TestConcessioniModel.getBaseFolder(),"relazione.pdf"))); - - client.registerFileSet(mongoId, prepareRequest(storage, - Concessione.Paths.imgByIndex(0),Files.getSiblings(TestConcessioniModel.getBaseFolder(),"immagine").get(0))); - - // POSIZIONAMENTO - - client.registerFileSet(mongoId, prepareRequest(storage, - Concessione.Paths.POSIZIONAMENTO,pos.toArray(new File[pos.size()]))); - - // PIANTE - Map.Entry>[] entries= piante.entrySet().toArray(new Map.Entry[0]); - for( int i= 0; i< piante.size();i++) { - // Set layer name - c=client.getById(mongoId); - String path=Concessione.Paths.piantaByIndex(i); - c.getContentByPath(path).setTitolo(" Pianta from "+entries[i].getKey()); - client.update(mongoId, Serialization.write(c)); - - //Set fileset - client.registerFileSet(mongoId, prepareRequest(storage,path, entries[i].getValue().toArray(new File[0]))); - } - - c=client.publish(mongoId); - - System.out.println("@@@ Concessione "+c.getNome()+"\t STATUS : "+ c.getReport().getStatus()); - - return c; +// Concessione c= TestConcessioniModel.prepareConcessione(piante.size(), 1); +// c.setNome("Mock for "+baseName+" ("+packageName+")"); +// c= client.createNew(c); +// String mongoId=c.getMongo_id(); +// +// // TEST DATA, DO NOT CARE +// client.registerFileSet(mongoId, prepareRequest(storage, +// Concessione.Paths.RELAZIONE,new File (TestConcessioniModel.getBaseFolder(),"relazione.pdf"))); +// +// client.registerFileSet(mongoId, prepareRequest(storage, +// Concessione.Paths.imgByIndex(0),Files.getSiblings(TestConcessioniModel.getBaseFolder(),"immagine").get(0))); +// +// // POSIZIONAMENTO +// +// client.registerFileSet(mongoId, prepareRequest(storage, +// Concessione.Paths.POSIZIONAMENTO,pos.toArray(new File[pos.size()]))); +// +// // PIANTE +// Map.Entry>[] entries= piante.entrySet().toArray(new Map.Entry[0]); +// for( int i= 0; i< piante.size();i++) { +// // Set layer name +// c=client.getById(mongoId); +// String path=Concessione.Paths.piantaByIndex(i); +// c.getContentByPath(path).setTitolo(" Pianta from "+entries[i].getKey()); +// client.update(mongoId, Serialization.write(c)); +// +// //Set fileset +// client.registerFileSet(mongoId, prepareRequest(storage,path, entries[i].getValue().toArray(new File[0]))); +// } +// +// c=client.publish(mongoId); +// +// System.out.println("@@@ Concessione "+c.getNome()+"\t STATUS : "+ c.getReport().getStatus()); +// +// return c; } }