Search in sources :

Example 61 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class SLDFileHandlerTest method testGetSLDContentsFile.

/**
 * Single file
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.sld.SLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFile() {
    assertNull(new SLDFileHandler().getSLDContents(null));
    URL url = SLDFileHandlerTest.class.getResource("/point/sld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        SLDFileHandler handler = new SLDFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        assertEquals(1, sldDataList.size());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        SLDData sldData = (SLDData) sldDataList.get(0);
        sldData.setSLDFile(saveFile);
        assertFalse(handler.save(null));
        assertTrue(handler.save(sldData));
        saveFile.delete();
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) SLDFileHandler(com.sldeditor.extension.filesystem.file.sld.SLDFileHandler) File(java.io.File) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Test(org.junit.Test)

Example 62 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class VectorFileHandlerTest method testGetSLDContentsFile.

/**
 * Single file
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.vector.VectorFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFile() {
    assertNull(new VectorFileHandler().getSLDContents(null));
    URL url = VectorFileHandlerTest.class.getResource("/point/sld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        VectorFileHandler handler = new VectorFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        assertNull(sldDataList);
        // Try with valid vector file
        FileTreeNode fileTreeNode2 = new FileTreeNode(parent, "point_attribute.shp");
        sldDataList = handler.getSLDContents(fileTreeNode2);
        assertTrue(sldDataList.isEmpty());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        SLDData sldData = new SLDData(null, "");
        sldData.setSLDFile(saveFile);
        assertFalse(handler.save(null));
        assertFalse(handler.save(sldData));
        saveFile.delete();
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) SLDDataInterface(com.sldeditor.common.SLDDataInterface) VectorFileHandler(com.sldeditor.extension.filesystem.file.vector.VectorFileHandler) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Test(org.junit.Test)

Example 63 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class YSLDToolTest method testSetSelectedItems.

/**
 * Test sld file.
 */
@Test
public void testSetSelectedItems() {
    YSLDTool tool = new YSLDTool();
    JPanel panel = tool.getPanel();
    ToolButton toSLD = null;
    ToolButton toYSLD = null;
    for (Component c : panel.getComponents()) {
        if (c instanceof ToolButton) {
            ToolButton button = (ToolButton) c;
            String toolTipText = button.getToolTipText();
            if (toolTipText.compareTo(Localisation.getString(YSLDTool.class, "YSLDTool.exportToSLD")) == 0) {
                toSLD = button;
            } else if (toolTipText.compareTo(Localisation.getString(YSLDTool.class, "YSLDTool.exportToYSLD")) == 0) {
                toYSLD = button;
            }
        }
    }
    File testFile1 = null;
    File testFile3 = null;
    try {
        testFile1 = File.createTempFile("invalid", ".tst");
        testFile3 = File.createTempFile("valid", ".ysld");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    assertFalse(toYSLD.isEnabled());
    tool.setSelectedItems(null, null);
    // Invalid file
    List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
    SLDData sldData1 = new SLDData(null, null);
    sldData1.setSLDFile(testFile1);
    sldDataList.add(sldData1);
    tool.setSelectedItems(null, sldDataList);
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    assertFalse(toYSLD.isEnabled());
    // Try with valid sld file
    sldDataList = new ArrayList<SLDDataInterface>();
    SLDData sldData2 = getSLDDataFile("/point/sld/point_simplepoint.sld");
    sldDataList.add(sldData2);
    tool.setSelectedItems(null, sldDataList);
    // YSLD should be enabled
    assertTrue(toYSLD.isEnabled());
    assertFalse(toSLD.isEnabled());
    toYSLD.doClick();
    // Try with valid ysld file
    sldDataList = new ArrayList<SLDDataInterface>();
    SLDData sldData3 = getSLDDataFile("/point/ysld/point_simplepoint.ysld");
    sldDataList.add(sldData3);
    tool.setSelectedItems(null, sldDataList);
    // SLD should be enabled
    assertTrue(toSLD.isEnabled());
    assertFalse(toYSLD.isEnabled());
    toSLD.doClick();
    // Try with valid sld and ysld files
    sldDataList = new ArrayList<SLDDataInterface>();
    sldDataList.add(sldData2);
    sldDataList.add(sldData3);
    tool.setSelectedItems(null, sldDataList);
    // SLD and YSLD should be enabled
    assertTrue(toSLD.isEnabled());
    assertTrue(toYSLD.isEnabled());
    testFile1.delete();
    testFile3.delete();
    tidyUpTempFiles(sldData2.getSLDFile());
    tidyUpTempFiles(sldData3.getSLDFile());
}
Also used : JPanel(javax.swing.JPanel) SLDData(com.sldeditor.common.data.SLDData) ToolButton(com.sldeditor.tool.ToolButton) SLDDataInterface(com.sldeditor.common.SLDDataInterface) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Component(java.awt.Component) File(java.io.File) YSLDTool(com.sldeditor.tool.ysld.YSLDTool) Test(org.junit.Test)

Example 64 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class YSLDFileHandlerTest method testGetSLDName.

/**
 * Check SLD name
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.sld.SLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDName() {
    YSLDFileHandler handler = new YSLDFileHandler();
    assertTrue(handler.getSLDName(null).compareTo("") == 0);
    SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.ysld"), "sldContents");
    String sldName = handler.getSLDName(sldData);
    assertTrue(sldName.compareTo("layer.ysld") == 0);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) YSLDFileHandler(com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 65 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class GeoServerInputTest method testUpdateConnectionDetails.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#updateConnectionDetails(com.sldeditor.common.data.GeoServerConnection, com.sldeditor.common.data.GeoServerConnection)}.
 */
@Test
public void testUpdateConnectionDetails() {
    GeoServerInput input = new GeoServerInput(null);
    GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
    // Add some GeoServer connections
    GeoServerConnection connection1 = new GeoServerConnection();
    connection1.setConnectionName("test connection 1");
    input.addNewConnection(connection1);
    GeoServerConnection connection2 = new GeoServerConnection();
    connection2.setConnectionName("test connection 2");
    input.addNewConnection(connection2);
    // Try null parameters
    input.updateConnectionDetails(null, null);
    // Delete connection details
    List<GeoServerConnection> listToDelete = new ArrayList<GeoServerConnection>();
    listToDelete.add(connection1);
    input.deleteConnections(listToDelete);
    GeoServerConnection connection1Updated = new GeoServerConnection();
    connection1Updated.setConnectionName("update test connection 1");
    input.addNewConnection(connection1Updated);
    // Update the connection details
    input.updateConnectionDetails(connection1, connection1Updated);
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
    SLDData sldData = new SLDData(styleWrapper, "sld contents");
    sldData.setConnectionData(connection1);
    // Try and save with the old GeoServer connection details
    assertFalse(input.save(sldData));
    // Try and save with the new GeoServer connection details
    sldData.setConnectionData(connection1Updated);
    assertTrue(input.save(sldData));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) StyleWrapper(com.sldeditor.common.data.StyleWrapper) ArrayList(java.util.ArrayList) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)68 Test (org.junit.Test)54 StyleWrapper (com.sldeditor.common.data.StyleWrapper)35 File (java.io.File)27 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)24 SLDDataInterface (com.sldeditor.common.SLDDataInterface)20 IOException (java.io.IOException)20 URL (java.net.URL)16 ArrayList (java.util.ArrayList)14 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)8 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)7 FileNotFoundException (java.io.FileNotFoundException)7 URISyntaxException (java.net.URISyntaxException)7 MalformedURLException (java.net.MalformedURLException)6 NamedLayer (org.geotools.styling.NamedLayer)6 Style (org.geotools.styling.Style)6 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 VersionData (com.sldeditor.common.vendoroption.VersionData)4