Search in sources :

Example 1 with YSLDTool

use of com.sldeditor.tool.ysld.YSLDTool in project sldeditor by robward-scisys.

the class YSLDToolTest method testPanel.

/**
 * Test get layer name.
 */
@Test
public void testPanel() {
    YSLDTool tool = new YSLDTool();
    assertTrue(tool.getPanel() != null);
}
Also used : YSLDTool(com.sldeditor.tool.ysld.YSLDTool) Test(org.junit.Test)

Example 2 with YSLDTool

use of com.sldeditor.tool.ysld.YSLDTool in project sldeditor by robward-scisys.

the class YSLDToolTest method testGetToolName.

/**
 * Test get tool name.
 */
@Test
public void testGetToolName() {
    YSLDTool tool = new YSLDTool();
    String toolName = tool.getToolName();
    assertTrue(toolName.compareTo("com.sldeditor.tool.ysld.YSLDTool") == 0);
}
Also used : YSLDTool(com.sldeditor.tool.ysld.YSLDTool) Test(org.junit.Test)

Example 3 with YSLDTool

use of com.sldeditor.tool.ysld.YSLDTool in project sldeditor by robward-scisys.

the class YSLDToolTest method testSupports.

/**
 * Test which file types the tool supports.
 */
@Test
public void testSupports() {
    YSLDTool tool = new YSLDTool();
    assertFalse(tool.supports(null, null, null));
    File testFile1 = null;
    File testFile2 = null;
    File testFile3 = null;
    try {
        testFile1 = File.createTempFile("invalid", ".tst");
        testFile2 = File.createTempFile("valid", ".sld");
        testFile3 = File.createTempFile("valid", ".ysld");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Try with invalid file
    try {
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        assertNotNull(testFile1);
        nodeTypeList.add(new FileTreeNode(testFile1.getParentFile(), testFile1.getName()));
        assertFalse(tool.supports(null, nodeTypeList, null));
    } catch (SecurityException | FileNotFoundException e) {
        e.printStackTrace();
    }
    // Try with valid sld file
    try {
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        nodeTypeList.add(new FileTreeNode(testFile2.getParentFile(), testFile2.getName()));
        assertTrue(tool.supports(null, nodeTypeList, null));
    } catch (SecurityException | FileNotFoundException e) {
        e.printStackTrace();
    }
    // Try with valid ysld file
    try {
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        nodeTypeList.add(new FileTreeNode(testFile3.getParentFile(), testFile3.getName()));
        assertTrue(tool.supports(null, nodeTypeList, null));
    } catch (SecurityException | FileNotFoundException e) {
        e.printStackTrace();
    }
    // Try with several files
    try {
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        nodeTypeList.add(new FileTreeNode(testFile1.getParentFile(), testFile1.getName()));
        nodeTypeList.add(new FileTreeNode(testFile2.getParentFile(), testFile2.getName()));
        nodeTypeList.add(new FileTreeNode(testFile3.getParentFile(), testFile3.getName()));
        assertFalse(tool.supports(null, nodeTypeList, null));
    } catch (SecurityException | FileNotFoundException e) {
        e.printStackTrace();
    }
    testFile1.delete();
    testFile2.delete();
    testFile3.delete();
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) YSLDTool(com.sldeditor.tool.ysld.YSLDTool) NodeInterface(com.sldeditor.common.NodeInterface) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Test(org.junit.Test)

Example 4 with YSLDTool

use of com.sldeditor.tool.ysld.YSLDTool 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)

Aggregations

YSLDTool (com.sldeditor.tool.ysld.YSLDTool)4 Test (org.junit.Test)4 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 NodeInterface (com.sldeditor.common.NodeInterface)1 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 SLDData (com.sldeditor.common.data.SLDData)1 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)1 ToolButton (com.sldeditor.tool.ToolButton)1 Component (java.awt.Component)1 FileNotFoundException (java.io.FileNotFoundException)1 JPanel (javax.swing.JPanel)1