Search in sources :

Example 1 with SLDEditorFileHandler

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

the class SLDFileEditorHandlerTest method testGetSLDContents.

/**
 * Test method for {@link com.sldeditor.extension.filesystem.file.sldeditor.SLDEditorFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContents() {
    assertNull(new SLDEditorFileHandler().getSLDContents(null));
    URL url = SLDFileEditorHandlerTest.class.getResource("/point/sld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    System.out.println(url.toString());
    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 sldEditorFile = File.createTempFile(getClass().getSimpleName(), ".sldeditor");
        SLDData sldData = (SLDData) sldDataList.get(0);
        sldData.setSldEditorFile(sldEditorFile);
        SLDEditorFileHandler editorFileHandler = new SLDEditorFileHandler();
        assertFalse(handler.save(null));
        assertTrue(editorFileHandler.save(sldData));
        SLDEditorFileHandler editorFileHandler2 = new SLDEditorFileHandler();
        List<SLDDataInterface> actualSldDataList = editorFileHandler2.open(sldEditorFile);
        assertEquals(1, actualSldDataList.size());
        FileTreeNode editorFileTreeNode = new FileTreeNode(sldEditorFile.getParentFile(), sldEditorFile.getName());
        List<SLDDataInterface> actualSldDataList2 = editorFileHandler2.getSLDContents(editorFileTreeNode);
        assertEquals(1, actualSldDataList2.size());
        sldEditorFile.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) SLDEditorFileHandler(com.sldeditor.extension.filesystem.file.sldeditor.SLDEditorFileHandler) 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)

Aggregations

SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 SLDData (com.sldeditor.common.data.SLDData)1 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)1 SLDFileHandler (com.sldeditor.extension.filesystem.file.sld.SLDFileHandler)1 SLDEditorFileHandler (com.sldeditor.extension.filesystem.file.sldeditor.SLDEditorFileHandler)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 Test (org.junit.Test)1