package org.gcube.application.geoportal.common;

import lombok.extern.slf4j.Slf4j;
import org.gcube.application.geoportal.common.utils.Files;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertTrue;

@Slf4j
public class FilesTests {

    static File baseFolder=new File("../test-data/concessioni");

    @Test
    public void testNames(){
       for(String name : baseFolder.list()){
           if(name.contains(".")) {
               String originalExtension = name.substring(name.indexOf("."));
               String obtained = Files.fixFilename(name);
               log.info(name + "->" + obtained + "[" + originalExtension + "]");
               assertTrue(obtained.endsWith(originalExtension));
           }
       }
    }

    @Test
    public void testClustering() throws IOException {
        Map<String, List<File>> map=Files.getAllShapeSet(baseFolder.getParentFile(),true);
        map.forEach((k, v)->{
            System.out.println(k);
            v.forEach(f->{System.out.println(f.getName());});
        });

        assertTrue(map.get(new File(baseFolder,"pos.shp").getAbsolutePath()).size()==5);
        assertTrue(map.get(new File(baseFolder,"pianta.shp").getAbsolutePath()).size()==8);
    }

}
