Search in sources :

Example 26 with SLDData

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

the class GeoServerInputTest method testDeleteNodes.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#deleteNodes(com.sldeditor.common.NodeInterface, java.util.List)}.
 */
@Test
public void testDeleteNodes() {
    GeoServerInput input = new GeoServerInput(null);
    GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    rootNode = new DefaultMutableTreeNode("Root");
    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    input.populate(tree, model, rootNode);
    URL url = SLDFileHandlerTest.class.getResource("/sld/point_attribute.sld");
    List<SLDDataInterface> sldDataList = input.open(url);
    assertNull(sldDataList);
    GeoServerConnection connection1 = new GeoServerConnection();
    connection1.setConnectionName("test connection 1");
    // Add some GeoServer connections
    input.addNewConnection(connection1);
    // Try null parameters
    assertFalse(input.copyNodes(null, null));
    // Try with valid parameters
    // CHECKSTYLE:OFF
    GeoServerWorkspaceNode workspaceTreeNode = new GeoServerWorkspaceNode(input, connection1, "test workspace", false);
    // CHECKSTYLE:ON
    // Create test data
    List<SLDDataInterface> sldToDeleteList = new ArrayList<SLDDataInterface>();
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
    SLDData sldData = new SLDData(styleWrapper, "sld contents");
    sldData.setConnectionData(connection1);
    sldToDeleteList.add(sldData);
    input.deleteNodes(null, null);
    input.deleteNodes(workspaceTreeNode, null);
    input.deleteNodes(null, sldToDeleteList);
    // Try with valid parameters
    input.deleteNodes(workspaceTreeNode, sldToDeleteList);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) GeoServerWorkspaceNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) ArrayList(java.util.ArrayList) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 27 with SLDData

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

the class GeoServerInputTest method testGeoServerInput.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#GeoServerInput(com.sldeditor.common.ToolSelectionInterface)}.
 */
@Test
public void testGeoServerInput() {
    GeoServerInput input = new GeoServerInput(null);
    GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode("Root");
        DefaultTreeModel model = new DefaultTreeModel(rootNode);
        input.populate(tree, model, rootNode);
        URL url = SLDFileHandlerTest.class.getResource("/sld/point_attribute.sld");
        List<SLDDataInterface> sldDataList = input.open(url);
        assertNull(sldDataList);
        GeoServerConnection connection1 = new GeoServerConnection();
        connection1.setConnectionName("test connection 1");
        StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
        GeoServerStyleNode styleTreeNode = new GeoServerStyleNode(input, connection1, styleWrapper);
        // Try with no known GeoServer connections
        assertNull(input.getSLDContents(styleTreeNode));
        // Add some GeoServer connections
        input.addNewConnection(connection1);
        GeoServerConnection connection2 = new GeoServerConnection();
        connection2.setConnectionName("test connection 2");
        input.addNewConnection(connection2);
        List<SLDDataInterface> sldDataContentsList = input.getSLDContents(styleTreeNode).getSldData();
        assertEquals(1, sldDataContentsList.size());
        SLDData sldData = (SLDData) sldDataContentsList.get(0);
        // Try saving a null object
        assertFalse(input.save(null));
        // Save valid sld data
        assertTrue(input.save(sldData));
        // Try and save to a connection that doe snot exists
        GeoServerConnection connection3 = new GeoServerConnection();
        connection2.setConnectionName("test connection 3");
        sldData.setConnectionData(connection3);
        assertFalse(input.save(sldData));
        // Check how many connections we have
        assertEquals(2, input.getConnectionDetails().size());
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) GeoServerStyleNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 28 with SLDData

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

the class GeoServerClientTest method testInitialiseWithValidConnection.

/**
 * Only works if a default GeoServer instance is running
 *
 * <p>Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#initialise(com.sldeditor.extension.filesystem.geoserver.GeoServerReadProgressInterface, com.sldeditor.common.data.GeoServerConnection)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#retrieveData()}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#connect()}. Test
 * method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getStyle(com.sldeditor.common.data.StyleWrapper)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getStyle(com.sldeditor.common.data.StyleWrapper)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#uploadSLD(com.sldeditor.common.data.StyleWrapper, java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getWorkspaceList()}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#refreshWorkspace(java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#deleteStyle(com.sldeditor.common.data.StyleWrapper)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#disconnect()}.
 */
@Ignore
@Test
public void testInitialiseWithValidConnection() {
    GeoServerClient client = new GeoServerClient();
    TestProgressClass progress = new TestProgressClass();
    client.initialise(progress, testConnection);
    assertTrue(client.connect());
    assertEquals(testConnection, client.getConnection());
    List<String> actualWorkspaceList = client.getWorkspaceList();
    assertTrue(actualWorkspaceList.size() > 0);
    client.retrieveData();
    int count = 0;
    while (!progress.hasFinished() && count < 50) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count++;
    }
    assertTrue(progress.hasFinished());
    // CHECKSTYLE:OFF
    int actualNoOfStyles = progress.styleTotal;
    // CHECKSTYLE:ON
    // Retrieve style
    StyleWrapper styleWrapper = new StyleWrapper(client.getDefaultWorkspaceName(), "point");
    String sldContents = client.getStyle(styleWrapper);
    assertTrue(sldContents != null);
    SLDData sldData = new SLDData(styleWrapper, sldContents);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    assertEquals("default_point", sld.layers().get(0).getName());
    // Upload as new style
    String timeString = "" + System.currentTimeMillis();
    String styleName = "New_Test_style_" + timeString;
    styleWrapper.setStyle(styleName);
    assertTrue(client.uploadSLD(styleWrapper, sldContents));
    List<StyleWrapper> stylesToDeleteList = new ArrayList<StyleWrapper>();
    stylesToDeleteList.add(styleWrapper.clone());
    // Replace the existing style
    StyledLayer styledLayer = sld.layers().get(0);
    styledLayer.setName("test point sld");
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    String updatedSLDBody = sldWriter.encodeSLD(null, sld);
    assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
    // Change the workspace name - invalid
    styleWrapper.setWorkspace("Test workspace");
    assertFalse(client.uploadSLD(styleWrapper, updatedSLDBody));
    // Change the workspace name - valid
    String expectedWorkspace = "Test_workspace_" + timeString;
    styleWrapper.setWorkspace(expectedWorkspace);
    assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
    stylesToDeleteList.add(styleWrapper.clone());
    actualWorkspaceList = client.getWorkspaceList();
    assertTrue(actualWorkspaceList.contains(expectedWorkspace));
    // Update the contents
    styledLayer.setName("updated test point sld");
    updatedSLDBody = sldWriter.encodeSLD(null, sld);
    assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
    // Check refresh workspace works
    client.refreshWorkspace(client.getDefaultWorkspaceName());
    count = 0;
    while (!progress.hasFinished() && count < 50) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count++;
    }
    assertTrue(progress.hasFinished());
    assertEquals(actualNoOfStyles + 1, progress.styleTotal);
    // 
    for (StyleWrapper styleToDelete : stylesToDeleteList) {
        System.out.println("Deleting style : " + styleToDelete.getWorkspace() + "/" + styleToDelete.getStyle());
        assertTrue(client.deleteStyle(styleToDelete));
    }
    assertFalse(client.deleteStyle(null));
    assertFalse(client.deleteStyle(new StyleWrapper()));
    StyleWrapper tmpStyle = styleWrapper.clone();
    tmpStyle.setStyle("invalid");
    assertFalse(client.deleteStyle(tmpStyle));
    tmpStyle = styleWrapper.clone();
    tmpStyle.setWorkspace("invalid");
    assertFalse(client.deleteStyle(tmpStyle));
    System.out.println("Deleting workspace : " + expectedWorkspace);
    assertTrue(client.deleteWorkspace(expectedWorkspace));
    client.disconnect();
    assertFalse(client.isConnected());
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayer(org.geotools.styling.StyledLayer) ArrayList(java.util.ArrayList) GeoServerClient(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 29 with SLDData

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

the class FileSystemExtensionTest method testSave.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.FileSystemExtension#save(com.sldeditor.common.SLDDataInterface)}.
 */
@Test
public void testSave() {
    FileSystemExtension fsExt = new FileSystemExtension();
    DummyExtension dummyExtension = new DummyExtension();
    List<FileSystemInterface> overrideExtensionList = new ArrayList<FileSystemInterface>();
    overrideExtensionList.add(dummyExtension);
    FileSystemExtensionFactory.override(overrideExtensionList);
    fsExt.initialise(null, null);
    // Try null parameter
    assertFalse(fsExt.save(null));
    assertTrue(fsExt.save(new SLDData(null, null)));
}
Also used : FileSystemExtension(com.sldeditor.extension.filesystem.FileSystemExtension) SLDData(com.sldeditor.common.data.SLDData) FileSystemInterface(com.sldeditor.common.filesystem.FileSystemInterface) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 30 with SLDData

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

the class FileSystemInputTest method testFileSystemInput.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.file.FileSystemInput#FileSystemInput(com.sldeditor.common.ToolSelectionInterface)}.
 */
@Test
public void testFileSystemInput() {
    FileSystemInput input = new FileSystemInput(null);
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode("Root");
        DefaultTreeModel model = new DefaultTreeModel(rootNode);
        input.populate(tree, model, rootNode);
        URL url = SLDFileHandlerTest.class.getResource("/point/sld/point_attribute.sld");
        List<SLDDataInterface> sldDataList = input.open(url);
        assertEquals(1, sldDataList.size());
        File parent = null;
        try {
            parent = new File(url.toURI());
            parent = parent.getParentFile();
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        List<SLDDataInterface> sldDataContentsList = input.getSLDContents(fileTreeNode).getSldData();
        assertEquals(1, sldDataContentsList.size());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        SLDData sldData = (SLDData) sldDataContentsList.get(0);
        sldData.setSLDFile(saveFile);
        assertFalse(input.save(null));
        assertTrue(input.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) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) FileNotFoundException(java.io.FileNotFoundException) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileSystemInput(com.sldeditor.extension.filesystem.file.FileSystemInput) File(java.io.File) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)68 Test (org.junit.Test)54 StyleWrapper (com.sldeditor.common.data.StyleWrapper)35 File (java.io.File)27 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)24 SLDDataInterface (com.sldeditor.common.SLDDataInterface)20 IOException (java.io.IOException)20 URL (java.net.URL)16 ArrayList (java.util.ArrayList)14 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)8 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)7 FileNotFoundException (java.io.FileNotFoundException)7 URISyntaxException (java.net.URISyntaxException)7 MalformedURLException (java.net.MalformedURLException)6 NamedLayer (org.geotools.styling.NamedLayer)6 Style (org.geotools.styling.Style)6 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 VersionData (com.sldeditor.common.vendoroption.VersionData)4