Search in sources :

Example 1 with YSLDFileHandler

use of com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler in project sldeditor by robward-scisys.

the class YSLDFileHandlerTest method testGetSLDContentsFile.

/**
 * Single file
 * Test method for {@link com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFile() {
    assertNull(new YSLDFileHandler().getSLDContents(null));
    URL url = YSLDFileHandlerTest.class.getResource("/point/ysld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_simplepoint.ysld");
        YSLDFileHandler handler = new YSLDFileHandler();
        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(), ".ysld");
        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) YSLDFileHandler(com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler) 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) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 2 with YSLDFileHandler

use of com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler in project sldeditor by robward-scisys.

the class YSLDFileHandlerTest method testGetSLDContentsFolder.

/**
 * Supply a folder name and retrieve all the ysld files in it
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFolder() {
    assertNull(new YSLDFileHandler().getSLDContents(null));
    URL url = SLDFileHandlerTest.class.getResource("/point/ysld");
    String folderName = "";
    File parent = null;
    try {
        parent = new File(url.toURI());
        folderName = parent.getName();
        parent = parent.getParentFile();
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, folderName);
        YSLDFileHandler handler = new YSLDFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        List<String> expectedLayerNameList = Arrays.asList("point_simplepoint.ysld");
        assertEquals(expectedLayerNameList.size(), sldDataList.size());
        for (SLDDataInterface sldData : sldDataList) {
            assertTrue(expectedLayerNameList.contains(sldData.getLayerName()));
        }
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileNotFoundException(java.io.FileNotFoundException) YSLDFileHandler(com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 3 with YSLDFileHandler

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

Aggregations

YSLDFileHandler (com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler)3 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)3 Test (org.junit.Test)3 SLDDataInterface (com.sldeditor.common.SLDDataInterface)2 SLDData (com.sldeditor.common.data.SLDData)2 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 IOException (java.io.IOException)1