Search in sources :

Example 41 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class SLDDataTest method testStyle.

/**
 * Test style.
 */
@Test
public void testStyle() {
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "style");
    SLDData data = new SLDData(styleWrapper, null);
    assertEquals(styleWrapper, data.getStyle());
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Test(org.junit.Test)

Example 42 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class ExternalFilenamesTest method testGetText.

/**
 * Test method for {@link com.sldeditor.common.utils.ExternalFilenames#getText(java.net.URL)}.
 */
@Test
public void testGetText() {
    assertNull(ExternalFilenames.getText(null, null));
    SLDData sldData = new SLDData(new StyleWrapper("workspace", "style"), "contents");
    File tempSLDFile = null;
    try {
        tempSLDFile = File.createTempFile(getClass().getSimpleName(), ".sld");
    } catch (IOException e1) {
        e1.printStackTrace();
        fail("Couldn't create temp test file");
    }
    String expectedFilename = "test.tst";
    // Try it with no SLD file set
    assertNull(ExternalFilenames.getFile(sldData, expectedFilename));
    // Now set the SLD file
    sldData.setSLDFile(tempSLDFile);
    String rootFolder = tempSLDFile.getParent();
    String expectedResult = File.separator + expectedFilename;
    File file = new File(rootFolder + expectedResult);
    try {
        String actualResult = ExternalFilenames.getText(sldData, file.toURI().toURL());
        assertEquals(expectedResult, actualResult);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    String actualFilename2 = new File(expectedFilename).getAbsolutePath();
    File file2 = new File(actualFilename2);
    try {
        assertEquals(actualFilename2, ExternalFilenames.getText(sldData, file2.toURI().toURL()));
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    tempSLDFile.delete();
}
Also used : SLDData(com.sldeditor.common.data.SLDData) MalformedURLException(java.net.MalformedURLException) StyleWrapper(com.sldeditor.common.data.StyleWrapper) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 43 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class ReloadManagerTest method testReloadFile.

/**
 * Test method for
 * {@link com.sldeditor.common.watcher.ReloadManager#fileAdded(java.nio.file.Path)}. Test method
 * for {@link com.sldeditor.common.watcher.ReloadManager#fileModified(java.nio.file.Path)}. Test
 * method for
 * {@link com.sldeditor.common.watcher.ReloadManager#fileDeleted(java.nio.file.Path)}. Test
 * method for
 * {@link com.sldeditor.common.watcher.ReloadManager#sldDataUpdated(com.sldeditor.common.SLDDataInterface, boolean)}.
 * Test method for
 * {@link com.sldeditor.common.watcher.ReloadManager#addListener(com.sldeditor.common.LoadSLDInterface)}.
 */
@Test
public void testReloadFile() {
    ReloadManager.getInstance().fileAdded(null);
    ReloadManager.getInstance().fileModified(null);
    ReloadManager.getInstance().fileDeleted(null);
    SLDData sldData = new SLDData(new StyleWrapper(), "");
    ReloadManager.getInstance().sldDataUpdated(sldData, true);
    File expectedFile = new File("/tmp/testFile.sld");
    Path path = expectedFile.toPath();
    // Try with no callback
    ReloadManager.getInstance().fileModified(path);
    DummyCallback callback = new DummyCallback();
    ReloadManager.getInstance().addListener(callback);
    assertEquals(0, callback.reloadCallbackCalled);
    // Set loaded file - should match
    sldData.setSLDFile(expectedFile);
    ReloadManager.getInstance().sldDataUpdated(sldData, true);
    ReloadManager.getInstance().fileModified(path);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(1, callback.reloadCallbackCalled);
    // Set loaded file - won't match
    callback.reloadCallbackCalled = 0;
    File expectedFile2 = new File("/tmp/differenttestFile.sld");
    path = expectedFile2.toPath();
    ReloadManager.getInstance().fileModified(path);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(0, callback.reloadCallbackCalled);
    // Now try valid multiple calls
    path = expectedFile.toPath();
    ReloadManager.getInstance().fileModified(path);
    ReloadManager.getInstance().fileModified(path);
    ReloadManager.getInstance().fileModified(path);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(1, callback.reloadCallbackCalled);
}
Also used : Path(java.nio.file.Path) SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) File(java.io.File) Test(org.junit.Test)

Example 44 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class GeoServerStyleNodeTest method testGeoServerLayerNode.

/**
 * Test method for {@link com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode#GeoServerStyleNode(com.sldeditor.common.filesystem.FileSystemInterface)}.
 */
@Test
public void testGeoServerLayerNode() {
    FileSystemInterface fileHandler = new DummyFileSystemInput();
    GeoServerConnection connection = new GeoServerConnection();
    connection.setConnectionName("test connection");
    connection.setUserName("test user name");
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer");
    GeoServerStyleNode node = new GeoServerStyleNode(fileHandler, connection, styleWrapper);
    assertEquals(fileHandler, node.getHandler());
    assertEquals(connection, node.getConnectionData());
    assertEquals(styleWrapper, node.getStyle());
    assertEquals(BuiltInDataFlavour.GEOSERVER_STYLE_DATAITEM_FLAVOUR, node.getDataFlavour());
    assertNull(node.getDestinationText());
}
Also used : FileSystemInterface(com.sldeditor.common.filesystem.FileSystemInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) GeoServerStyleNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode) Test(org.junit.Test)

Example 45 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class NewSLDPanel method showDialog.

/**
 * Show dialog.
 *
 * @param parent the parent
 * @return the created SLD if selected
 */
public List<SLDDataInterface> showDialog(JFrame parent) {
    List<SLDDataInterface> newSLDList = null;
    selected = null;
    if (parent != null) {
        this.setLocationRelativeTo(parent);
        int x = ((parent.getWidth() - getWidth()) / 2);
        int y = ((parent.getHeight() - getHeight()) / 2);
        this.setLocation(x, y);
    }
    setVisible(true);
    if (selected != null) {
        newSLDList = new ArrayList<SLDDataInterface>();
        StyledLayerDescriptor sld = selected.create();
        if (sldWriter == null) {
            sldWriter = SLDWriterFactory.createWriter(null);
        }
        newSLDList.add(new SLDData(new StyleWrapper(selected.getName()), sldWriter.encodeSLD(null, sld)));
        return newSLDList;
    }
    return null;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Aggregations

StyleWrapper (com.sldeditor.common.data.StyleWrapper)59 SLDData (com.sldeditor.common.data.SLDData)35 Test (org.junit.Test)31 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)15 File (java.io.File)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 ArrayList (java.util.ArrayList)12 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)10 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)9 List (java.util.List)9 GeoServerLayer (com.sldeditor.common.data.GeoServerLayer)8 IOException (java.io.IOException)8 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)7 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 GeoServerStyleNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5 HashMap (java.util.HashMap)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)4 NamedLayer (org.geotools.styling.NamedLayer)4