Search in sources :

Example 1 with SLDEditorMain

use of com.sldeditor.SLDEditorMain in project sldeditor by robward-scisys.

the class SLDEditorDockableLayoutTest method testCreateUI.

/**
 * Test method for {@link
 * com.sldeditor.ui.layout.SLDEditorDockableLayout#createUI(com.sldeditor.common.SLDEditorInterface,
 * com.sldeditor.ui.panels.SLDEditorUIPanels, java.util.List)}.
 */
@Test
void testCreateUI() {
    TestSLDEditor testSLDEditor = null;
    PrefData prefData = new PrefData();
    prefData.setUiLayoutClass(SLDEditorDockableLayout.class.getName());
    PrefManager.getInstance().setPrefData(prefData);
    try {
        testSLDEditor = TestSLDEditor.createAndShowGUI2(null, null, true, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    File tmpFolder = new File(System.getProperty("java.io.tmpdir"));
    String uiLayout = SLDEditorDockableLayout.class.getName();
    UILayoutInterface ui = UILayoutFactory.getUILayout(uiLayout);
    SLDEditorUIPanels uiMgr = SLDEditorUIPanels.getInstance();
    ui.createUI(new SLDEditorMain(testSLDEditor), uiMgr, new ArrayList<ExtensionInterface>());
    ui.writeLayout(tmpFolder.getAbsolutePath());
    ui.readLayout(tmpFolder.getAbsolutePath());
    File f = new File(tmpFolder, "layout.data");
    f.delete();
    assertEquals(uiLayout, SLDEditorDockableLayout.class.getName());
}
Also used : SLDEditorMain(com.sldeditor.SLDEditorMain) PrefData(com.sldeditor.common.preferences.PrefData) SLDEditorDockableLayout(com.sldeditor.ui.layout.SLDEditorDockableLayout) ExtensionInterface(com.sldeditor.extension.ExtensionInterface) SLDEditorUIPanels(com.sldeditor.ui.panels.SLDEditorUIPanels) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) UILayoutInterface(com.sldeditor.ui.layout.UILayoutInterface) Test(org.junit.jupiter.api.Test)

Example 2 with SLDEditorMain

use of com.sldeditor.SLDEditorMain in project sldeditor by robward-scisys.

the class SLDEditorDefaultLayoutTest method testCreateUI.

/**
 * Test method for {@link
 * com.sldeditor.ui.layout.SLDEditorDockableLayout#createUI(com.sldeditor.common.SLDEditorInterface,
 * com.sldeditor.ui.panels.SLDEditorUIPanels, java.util.List)}.
 */
@Test
void testCreateUI() {
    @SuppressWarnings("unused") TestSLDEditor testSLDEditor = null;
    PrefData prefData = new PrefData();
    prefData.setUiLayoutClass(SLDEditorDefaultLayout.class.getName());
    PrefManager.getInstance().setPrefData(prefData);
    try {
        testSLDEditor = TestSLDEditor.createAndShowGUI2(null, null, true, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    File tmpFolder = new File(System.getProperty("java.io.tmpdir"));
    String uiLayout = SLDEditorDefaultLayout.class.getName();
    UILayoutInterface ui = UILayoutFactory.getUILayout(uiLayout);
    SLDEditorUIPanels uiMgr = SLDEditorUIPanels.getInstance();
    ui.createUI(new SLDEditorMain(testSLDEditor), uiMgr, new ArrayList<ExtensionInterface>());
    ui.writeLayout(tmpFolder.getAbsolutePath());
    ui.readLayout(tmpFolder.getAbsolutePath());
    File f = new File(tmpFolder, "layout.data");
    f.delete();
    assertEquals(uiLayout, SLDEditorDefaultLayout.class.getName());
}
Also used : SLDEditorMain(com.sldeditor.SLDEditorMain) PrefData(com.sldeditor.common.preferences.PrefData) SLDEditorDefaultLayout(com.sldeditor.ui.layout.SLDEditorDefaultLayout) ExtensionInterface(com.sldeditor.extension.ExtensionInterface) SLDEditorUIPanels(com.sldeditor.ui.panels.SLDEditorUIPanels) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) UILayoutInterface(com.sldeditor.ui.layout.UILayoutInterface) Test(org.junit.jupiter.api.Test)

Example 3 with SLDEditorMain

use of com.sldeditor.SLDEditorMain in project sldeditor by robward-scisys.

the class SLDEditorOperationsTest method testReloadSLDFile.

/**
 * Test method for {@link com.sldeditor.SLDEditorOperations#reloadSLDFile()}.
 */
@Test
void testReloadSLDFile() {
    SLDEditorOperations.getInstance().reloadSLDFile();
    DummyExternalSLDFile external = new DummyExternalSLDFile();
    SLDEditorFile.getInstance().setSLDData(external.getSLDData());
    SLDEditorMain testObj = new SLDEditorMain(null);
    File f = null;
    try {
        f = File.createTempFile("test", ".sld");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    external.getSLDData().setSLDFile(f);
    try {
        testObj.saveFile(f.toURI().toURL());
    } catch (MalformedURLException e) {
        fail(e.getMessage());
    }
    assertTrue(f.exists());
    FileSystemExtensionFactory.getFileExtensionList(null);
    SLDEditorOperations.getInstance().reloadSLDFile();
    FileSystemExtensionFactory.override(null);
    f.delete();
}
Also used : SLDEditorMain(com.sldeditor.SLDEditorMain) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with SLDEditorMain

use of com.sldeditor.SLDEditorMain in project sldeditor by robward-scisys.

the class VectorToolTest method testVectorToolFileDataSource.

/**
 * Test method for {@link
 * com.sldeditor.tool.vector.VectorTool#VectorTool(com.sldeditor.common.SLDEditorInterface)}.
 */
@Test
public void testVectorToolFileDataSource() {
    TestMissingSLDAttributes testAttribute = new TestMissingSLDAttributes();
    List<CheckAttributeInterface> checkList = new ArrayList<CheckAttributeInterface>();
    checkList.add(testAttribute);
    CheckAttributeFactory.setOverrideCheckList(checkList);
    String testsldfile = "/polygon/sld/polygon_polygonwithdefaultlabel.sld";
    TestSLDEditor testSLDEditor = null;
    try {
        testSLDEditor = TestSLDEditor.createAndShowGUI2(null, null, true, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    InputStream inputStream = VectorToolTest.class.getResourceAsStream(testsldfile);
    if (inputStream == null) {
        assertNotNull(inputStream, "Failed to find sld test file : " + testsldfile);
    } else {
        File f = null;
        try {
            f = stream2file(inputStream);
            try {
                testSLDEditor.getTestInterface().openFile(f.toURI().toURL());
            } catch (NullPointerException nullException) {
                nullException.printStackTrace();
                StackTraceElement[] stackTraceElements = nullException.getStackTrace();
                System.out.println(stackTraceElements[0].getMethodName());
            }
            f.delete();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    // Fields extracted from the SLD file
    DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
    Collection<PropertyDescriptor> propertyList = dataSource.getPropertyDescriptorList();
    assertEquals(2, propertyList.size());
    Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>();
    for (PropertyDescriptor property : propertyList) {
        map.put(property.getName().getLocalPart(), property);
    }
    AttributeDescriptor name = (AttributeDescriptor) map.get("name");
    assertNotNull(name);
    GeometryDescriptor geometry = (GeometryDescriptor) map.get("geom");
    assertNotNull(geometry);
    Path tempFolder = null;
    try {
        tempFolder = Files.createTempDirectory(getClass().getSimpleName());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Failed to create temp folder in temp folder!");
    }
    TestVectorTool vectorTool = new TestVectorTool(new SLDEditorMain(new JPanel()));
    try {
        // Set a shape file as a data source - that matches the SLD
        File matchingShpFile = extractShapeFile(tempFolder.toFile(), "/test/sld_cookbook_polygon.zip");
        FileTreeNode fileTreeNode = new FileTreeNode(matchingShpFile.getParentFile(), matchingShpFile.getName());
        vectorTool.testSetDataSource(fileTreeNode);
        dataSource = DataSourceFactory.createDataSource(null);
        propertyList = dataSource.getPropertyDescriptorList();
        assertEquals(3, propertyList.size());
        map.clear();
        for (PropertyDescriptor property : propertyList) {
            map.put(property.getName().getLocalPart(), property);
        }
        name = (AttributeDescriptor) map.get("name");
        assertNotNull(name);
        geometry = (GeometryDescriptor) map.get("the_geom");
        assertNotNull(geometry);
        AttributeDescriptor pop = (AttributeDescriptor) map.get("pop");
        assertNotNull(pop);
        // Set a shape file as a data source - that does not match the SLD
        File nonMatchingShpFile = extractShapeFile(tempFolder.toFile(), "/test/states.zip");
        FileTreeNode fileTreeNode2 = new FileTreeNode(nonMatchingShpFile.getParentFile(), nonMatchingShpFile.getName());
        vectorTool.testSetDataSource(fileTreeNode2);
        dataSource = DataSourceFactory.createDataSource(null);
        propertyList = dataSource.getPropertyDescriptorList();
        assertEquals(23, propertyList.size());
        map.clear();
        for (PropertyDescriptor property : propertyList) {
            map.put(property.getName().getLocalPart(), property);
        }
        name = (AttributeDescriptor) map.get("name");
        assertNull(name);
        geometry = (GeometryDescriptor) map.get("the_geom");
        assertNotNull(geometry);
        pop = (AttributeDescriptor) map.get("pop");
        assertNull(pop);
        assertEquals(1, testAttribute.getMissingFieldList().size());
        assertEquals("name", testAttribute.getMissingFieldList().get(0));
        // Create SLD from shape file
        vectorTool.testImportFile(fileTreeNode);
        dataSource = DataSourceFactory.createDataSource(null);
        propertyList = dataSource.getPropertyDescriptorList();
        assertEquals(3, propertyList.size());
        map.clear();
        for (PropertyDescriptor property : propertyList) {
            map.put(property.getName().getLocalPart(), property);
        }
        name = (AttributeDescriptor) map.get("name");
        assertNotNull(name);
        geometry = (GeometryDescriptor) map.get("the_geom");
        assertNotNull(geometry);
        pop = (AttributeDescriptor) map.get("pop");
        assertNotNull(pop);
        // Release locks
        dataSource.reset();
    } catch (IOException e) {
        fail(e.getStackTrace().toString());
    }
    // Tidy up so the remaining unit tests are ok
    JFrame frame = Controller.getInstance().getFrame();
    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
    testSLDEditor = null;
    clearDown();
    // Delete the shape files we extracted
    purgeDirectory(tempFolder);
}
Also used : JPanel(javax.swing.JPanel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) JFrame(javax.swing.JFrame) CheckAttributeInterface(com.sldeditor.datasource.checks.CheckAttributeInterface) Path(java.nio.file.Path) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) SLDEditorMain(com.sldeditor.SLDEditorMain) WindowEvent(java.awt.event.WindowEvent) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with SLDEditorMain

use of com.sldeditor.SLDEditorMain in project sldeditor by robward-scisys.

the class VectorToolTest method testVectorToolDBDataSource.

@Test
public void testVectorToolDBDataSource() {
    TestMissingSLDAttributes testAttribute = new TestMissingSLDAttributes();
    List<CheckAttributeInterface> checkList = new ArrayList<CheckAttributeInterface>();
    checkList.add(testAttribute);
    CheckAttributeFactory.setOverrideCheckList(checkList);
    String testsldfile = "/polygon/sld/polygon_polygonwithdefaultlabel.sld";
    TestSLDEditor testSLDEditor = null;
    try {
        testSLDEditor = TestSLDEditor.createAndShowGUI2(null, null, true, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    RenderPanelImpl.setUnderTest(true);
    InputStream inputStream = VectorToolTest.class.getResourceAsStream(testsldfile);
    if (inputStream == null) {
        assertNotNull(inputStream, "Failed to find sld test file : " + testsldfile);
    } else {
        File f = null;
        try {
            f = stream2file(inputStream);
            try {
                testSLDEditor.getTestInterface().openFile(f.toURI().toURL());
            } catch (NullPointerException nullException) {
                nullException.printStackTrace();
                StackTraceElement[] stackTraceElements = nullException.getStackTrace();
                System.out.println(stackTraceElements[0].getMethodName());
            }
            f.delete();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    // Fields extracted from the SLD file
    DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
    Collection<PropertyDescriptor> propertyList = dataSource.getPropertyDescriptorList();
    assertEquals(2, propertyList.size());
    Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>();
    for (PropertyDescriptor property : propertyList) {
        map.put(property.getName().getLocalPart(), property);
    }
    AttributeDescriptor name = (AttributeDescriptor) map.get("name");
    assertNotNull(name);
    GeometryDescriptor geometry = (GeometryDescriptor) map.get("geom");
    assertNotNull(geometry);
    Path tempFolder = null;
    try {
        tempFolder = Files.createTempDirectory(getClass().getSimpleName());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Failed to create temp folder in temp folder!");
    }
    TestVectorTool vectorTool = new TestVectorTool(new SLDEditorMain(new JPanel()));
    try {
        InputStream gpkgInputStream = VectorToolTest.class.getResourceAsStream("/test/sld_cookbook_polygon.gpkg");
        final File gpkgFile = new File(tempFolder.toFile(), "sld_cookbook_polygon.gpkg");
        try (FileOutputStream out = new FileOutputStream(gpkgFile)) {
            IOUtils.copy(gpkgInputStream, out);
        }
        DatabaseConnection databaseConnection = DatabaseConnectionFactory.getConnection(gpkgFile.getAbsolutePath());
        DatabaseFeatureClassNode dbFCTreeNode = new DatabaseFeatureClassNode(null, databaseConnection, "sld_cookbook_polygon");
        DatabaseConnectionManager.getInstance().addNewConnection(null, databaseConnection);
        vectorTool.testSetDataSource(dbFCTreeNode);
        dataSource = DataSourceFactory.createDataSource(null);
        propertyList = dataSource.getPropertyDescriptorList();
        assertEquals(3, propertyList.size());
        map.clear();
        for (PropertyDescriptor property : propertyList) {
            map.put(property.getName().getLocalPart(), property);
        }
        name = (AttributeDescriptor) map.get("name");
        assertNotNull(name);
        geometry = (GeometryDescriptor) map.get("geometry");
        assertNotNull(geometry);
        AttributeDescriptor pop = (AttributeDescriptor) map.get("pop");
        assertNotNull(pop);
        // Create SLD from geopackage layer
        vectorTool.testImportFeatureClass(dbFCTreeNode);
        dataSource = DataSourceFactory.createDataSource(null);
        propertyList = dataSource.getPropertyDescriptorList();
        assertEquals(3, propertyList.size());
        map.clear();
        for (PropertyDescriptor property : propertyList) {
            map.put(property.getName().getLocalPart(), property);
        }
        name = (AttributeDescriptor) map.get("name");
        assertNotNull(name);
        geometry = (GeometryDescriptor) map.get("geometry");
        assertNotNull(geometry);
        pop = (AttributeDescriptor) map.get("pop");
        assertNotNull(pop);
        // Release locks
        dataSource.reset();
    } catch (IOException e) {
        fail(e.getStackTrace().toString());
    }
    // Tidy up so the remaining unit tests are ok
    JFrame frame = Controller.getInstance().getFrame();
    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
    testSLDEditor = null;
    clearDown();
    // Delete the shape files we extracted
    purgeDirectory(tempFolder);
}
Also used : JPanel(javax.swing.JPanel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) JFrame(javax.swing.JFrame) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) CheckAttributeInterface(com.sldeditor.datasource.checks.CheckAttributeInterface) Path(java.nio.file.Path) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SLDEditorMain(com.sldeditor.SLDEditorMain) DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) FileOutputStream(java.io.FileOutputStream) WindowEvent(java.awt.event.WindowEvent) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

SLDEditorMain (com.sldeditor.SLDEditorMain)5 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)5 File (java.io.File)5 Test (org.junit.jupiter.api.Test)5 IOException (java.io.IOException)3 PrefData (com.sldeditor.common.preferences.PrefData)2 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)2 CheckAttributeInterface (com.sldeditor.datasource.checks.CheckAttributeInterface)2 ExtensionInterface (com.sldeditor.extension.ExtensionInterface)2 UILayoutInterface (com.sldeditor.ui.layout.UILayoutInterface)2 SLDEditorUIPanels (com.sldeditor.ui.panels.SLDEditorUIPanels)2 WindowEvent (java.awt.event.WindowEvent)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ZipInputStream (java.util.zip.ZipInputStream)2 JFrame (javax.swing.JFrame)2