Search in sources :

Example 1 with VectorFileHandler

use of com.sldeditor.extension.filesystem.file.vector.VectorFileHandler in project sldeditor by robward-scisys.

the class VectorFileHandlerTest method testGetSLDName.

/**
 * Supply a folder name and retrieve all the sld files in it
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.vector.VectorFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDName() {
    VectorFileHandler handler = new VectorFileHandler();
    assertTrue(handler.getSLDName(null).compareTo("") == 0);
    SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), "sldContents");
    String sldName = handler.getSLDName(sldData);
    assertTrue(sldName.compareTo("layer.sld") == 0);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) VectorFileHandler(com.sldeditor.extension.filesystem.file.vector.VectorFileHandler) Test(org.junit.Test)

Example 2 with VectorFileHandler

use of com.sldeditor.extension.filesystem.file.vector.VectorFileHandler 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)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)2 VectorFileHandler (com.sldeditor.extension.filesystem.file.vector.VectorFileHandler)2 Test (org.junit.Test)2 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1