Search in sources :

Example 1 with RasterFileHandler

use of com.sldeditor.extension.filesystem.file.raster.RasterFileHandler in project sldeditor by robward-scisys.

the class RasterFileHandlerTest method testGetSLDName.

/**
 * Supply a folder name and retrieve all the sld files in it
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.raster.RasterFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDName() {
    RasterFileHandler handler = new RasterFileHandler();
    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) RasterFileHandler(com.sldeditor.extension.filesystem.file.raster.RasterFileHandler) Test(org.junit.Test)

Example 2 with RasterFileHandler

use of com.sldeditor.extension.filesystem.file.raster.RasterFileHandler in project sldeditor by robward-scisys.

the class RasterFileHandlerTest method testGetSLDContentsFile.

/**
 * Single file
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.raster.RasterFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFile() {
    assertNull(new RasterFileHandler().getSLDContents(null));
    URL url = RasterFileHandlerTest.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");
        RasterFileHandler handler = new RasterFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        assertNull(sldDataList);
        // Try with valid vector file
        FileTreeNode fileTreeNode2 = new FileTreeNode(parent, "point_attribute.tif");
        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) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RasterFileHandler(com.sldeditor.extension.filesystem.file.raster.RasterFileHandler) 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 RasterFileHandler (com.sldeditor.extension.filesystem.file.raster.RasterFileHandler)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