Search in sources :

Example 1 with DummyExternalSLDFile

use of com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile in project sldeditor by robward-scisys.

the class LegendPanelImageTest method testRenderSymbol.

/**
 * Test method for {@link com.sldeditor.ui.legend.LegendPanelImage#renderSymbol()}.
 */
@Test
void testRenderSymbol() {
    TestLegendPanelImage testObj = new TestLegendPanelImage();
    DummyExternalSLDFile external = new DummyExternalSLDFile();
    SelectedSymbol.getInstance().setSld(external.getSLD());
    testObj.renderSymbol();
    testObj.setFilenameDisplayed(true);
    testObj.showFilenamePressed();
    testObj.setFilenameDisplayed(false);
    testObj.showFilenamePressed();
    testObj.setStyleNameDisplayed(true);
    testObj.showStyleNamePressed();
    testObj.setStyleNameDisplayed(false);
    testObj.showStyleNamePressed();
    // Empty style layer name
    StyledLayer styledLayer = external.getSLD().layers().get(0);
    styledLayer.setName(null);
    testObj.setStyleNameDisplayed(true);
    testObj.showStyleNamePressed();
    File selectedFile = null;
    try {
        selectedFile = File.createTempFile("test", ".sld");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    // Write legend image with no file filter
    Image image = testObj.getImageIcon().getImage();
    File f = null;
    try {
        f = testObj.writeLegendImage(null, selectedFile, image);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    assertTrue(f.exists());
    f.delete();
    selectedFile.delete();
    // Write legend image with file filter and no file suffix
    try {
        selectedFile = File.createTempFile("test", "test");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    image = testObj.getImageIcon().getImage();
    try {
        f = testObj.writeLegendImage(new ImageFilter(ImageFileExtensionUtils.PNG), selectedFile, image);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    assertTrue(f.exists());
    f.delete();
    Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection stringSelection = new StringSelection("cleared clipboard");
    c.setContents(stringSelection, null);
    testObj.copyToClipboard();
    c = Toolkit.getDefaultToolkit().getSystemClipboard();
    assertTrue(c.isDataFlavorAvailable(DataFlavor.imageFlavor));
    selectedFile.delete();
}
Also used : DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) StyledLayer(org.geotools.styling.StyledLayer) ImageFilter(com.sldeditor.ui.legend.filechooser.ImageFilter) IOException(java.io.IOException) Clipboard(java.awt.datatransfer.Clipboard) Image(java.awt.Image) LegendPanelImage(com.sldeditor.ui.legend.LegendPanelImage) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) File(java.io.File) StringSelection(java.awt.datatransfer.StringSelection) Test(org.junit.jupiter.api.Test)

Example 2 with DummyExternalSLDFile

use of com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile in project sldeditor by robward-scisys.

the class SLDEditorOperationsTest method testReloadSLDFile.

/**
 * Test method for {@link com.sldeditor.SLDEditorOperations#reloadSLDFile()}.
 */
@Test
void testReloadSLDFile() {
    SLDEditorOperations.getInstance().reloadSLDFile();
    DummyExternalSLDFile external = new DummyExternalSLDFile();
    SLDEditorFile.getInstance().setSLDData(external.getSLDData());
    SLDEditorMain testObj = new SLDEditorMain(null);
    File f = null;
    try {
        f = File.createTempFile("test", ".sld");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    external.getSLDData().setSLDFile(f);
    try {
        testObj.saveFile(f.toURI().toURL());
    } catch (MalformedURLException e) {
        fail(e.getMessage());
    }
    assertTrue(f.exists());
    FileSystemExtensionFactory.getFileExtensionList(null);
    SLDEditorOperations.getInstance().reloadSLDFile();
    FileSystemExtensionFactory.override(null);
    f.delete();
}
Also used : SLDEditorMain(com.sldeditor.SLDEditorMain) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with DummyExternalSLDFile

use of com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile in project sldeditor by robward-scisys.

the class SLDEditorMainTest method testChooseNewSLD.

/**
 * Test method for {@link com.sldeditor.SLDEditorMain#chooseNewSLD()}.
 */
@Test
void testChooseNewSLD() {
    TestSLDEditorMain testObj = new TestSLDEditorMain(new JPanel());
    JFrame frame = new JFrame();
    Controller.getInstance().setFrame(frame);
    testObj.newSLD(null);
    // SLD file
    DummyExternalSLDFile external = new DummyExternalSLDFile();
    List<SLDDataInterface> newSLDList = new ArrayList<SLDDataInterface>();
    newSLDList.add(external.getSLDData());
    testObj.newSLD(newSLDList);
}
Also used : JPanel(javax.swing.JPanel) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) JFrame(javax.swing.JFrame) SLDDataInterface(com.sldeditor.common.SLDDataInterface) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 4 with DummyExternalSLDFile

use of com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile in project sldeditor by robward-scisys.

the class SLDEditorMainTest method testSaveFile.

/**
 * Test method for {@link com.sldeditor.SLDEditorMain#saveFile(java.net.URL)}.
 */
@Test
void testSaveFile() {
    TestSLDEditorMain testObj = new TestSLDEditorMain(new JPanel());
    testObj.saveFile(null);
    // SLD file
    DummyExternalSLDFile external = new DummyExternalSLDFile();
    SLDEditorFile.getInstance().setSLDData(external.getSLDData());
    File f = null;
    try {
        f = File.createTempFile("test", ".sld");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    try {
        testObj.saveFile(f.toURI().toURL());
    } catch (MalformedURLException e) {
        fail(e.getMessage());
    }
    assertTrue(f.exists());
    f.delete();
}
Also used : JPanel(javax.swing.JPanel) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with DummyExternalSLDFile

use of com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile in project sldeditor by robward-scisys.

the class SLDEditorMainTest method testUpdateWindowTitle.

/**
 * Test method for {@link com.sldeditor.SLDEditorMain#updateWindowTitle(boolean)}.
 */
@Test
void testUpdateWindowTitle() {
    TestSLDEditorMain testObj = new TestSLDEditorMain(new JPanel());
    JFrame frame = new JFrame();
    Controller.getInstance().setFrame(frame);
    // No SLD Editor file and SLD file
    testObj.updateWindowTitle(false);
    String actual = Controller.getInstance().getFrame().getTitle();
    assertEquals(SLDEditorMain.generateApplicationTitleString() + " -  ", actual);
    testObj.updateWindowTitle(true);
    actual = Controller.getInstance().getFrame().getTitle();
    assertEquals(SLDEditorMain.generateApplicationTitleString() + " - *", actual);
    // SLD Editor file and SLD file
    DummyExternalSLDFile external = new DummyExternalSLDFile();
    SLDEditorFile.getInstance().setSLDData(external.getSLDData());
    String sldEditorFile = "tmp.sldeditor";
    SLDEditorFile.getInstance().setSldEditorFile(new File(sldEditorFile));
    // Data not updated
    testObj.updateWindowTitle(false);
    actual = Controller.getInstance().getFrame().getTitle();
    assertEquals(SLDEditorMain.generateApplicationTitleString() + " - " + sldEditorFile + " - " + external.getSLDData().getLayerName() + " ", actual);
    // Data updated
    testObj.updateWindowTitle(true);
    actual = Controller.getInstance().getFrame().getTitle();
    assertEquals(SLDEditorMain.generateApplicationTitleString() + " - " + sldEditorFile + " - " + external.getSLDData().getLayerName() + "*", actual);
    // Just sld layer
    SLDEditorFile.getInstance().setSldEditorFile(null);
    testObj.updateWindowTitle(true);
    actual = Controller.getInstance().getFrame().getTitle();
    assertEquals(SLDEditorMain.generateApplicationTitleString() + " - " + external.getSLDData().getLayerName() + "*", actual);
}
Also used : JPanel(javax.swing.JPanel) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) JFrame(javax.swing.JFrame) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

DummyExternalSLDFile (com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile)7 Test (org.junit.jupiter.api.Test)7 JPanel (javax.swing.JPanel)5 File (java.io.File)4 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)3 IOException (java.io.IOException)3 JFrame (javax.swing.JFrame)3 MalformedURLException (java.net.MalformedURLException)2 SLDEditorMain (com.sldeditor.SLDEditorMain)1 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 LegendPanelImage (com.sldeditor.ui.legend.LegendPanelImage)1 ImageFilter (com.sldeditor.ui.legend.filechooser.ImageFilter)1 Image (java.awt.Image)1 Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 ArrayList (java.util.ArrayList)1 StyledLayer (org.geotools.styling.StyledLayer)1