Search in sources :

Example 1 with GeoServerClient

use of com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient 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 2 with GeoServerClient

use of com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient in project sldeditor by robward-scisys.

the class GeoServerClientTest method testInitialiseWithInvalidConnection.

/**
 * 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#connect()}.
 */
@Test
public void testInitialiseWithInvalidConnection() {
    GeoServerClient client = new GeoServerClient();
    GeoServerConnection invalidTestConnection = new GeoServerConnection();
    invalidTestConnection.setConnectionName("Invalid Test Connection");
    try {
        invalidTestConnection.setUrl(new URL("http://invalid.url.com"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    client.initialise(null, invalidTestConnection);
    assertFalse(client.connect());
    assertEquals(invalidTestConnection, client.getConnection());
}
Also used : MalformedURLException(java.net.MalformedURLException) GeoServerClient(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) Test(org.junit.Test)

Example 3 with GeoServerClient

use of com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient in project sldeditor by robward-scisys.

the class GeoServerClientTest method testGeoServerClient.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#GeoServerClient()}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#isConnected()}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getConnection()}.
 */
@Test
public void testGeoServerClient() {
    GeoServerClient client = new GeoServerClient();
    assertFalse(client.connect());
    assertNull(client.getConnection());
}
Also used : GeoServerClient(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient) Test(org.junit.Test)

Example 4 with GeoServerClient

use of com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient in project sldeditor by robward-scisys.

the class GeoServerClientTest method testUpdateLayerStyles.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#updateLayerStyles(com.sldeditor.common.data.GeoServerLayer, com.sldeditor.common.data.StyleWrapper)}.
 */
@Test
public void testUpdateLayerStyles() {
    GeoServerClient client = new GeoServerClient();
    assertFalse(client.updateLayerStyles(null));
}
Also used : GeoServerClient(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient) Test(org.junit.Test)

Example 5 with GeoServerClient

use of com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient in project sldeditor by robward-scisys.

the class GeoServerClientTest method testIsDefaultWorkspace.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#isDefaultWorkspace(java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getDefaultWorkspaceName()}.
 */
@Test
public void testIsDefaultWorkspace() {
    String workspaceName = "test workspace";
    GeoServerClient client = new GeoServerClient();
    assertFalse(client.isDefaultWorkspace(workspaceName));
    assertTrue(client.isDefaultWorkspace(client.getDefaultWorkspaceName()));
}
Also used : GeoServerClient(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient) Test(org.junit.Test)

Aggregations

GeoServerClient (com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient)5 Test (org.junit.Test)5 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)1 SLDData (com.sldeditor.common.data.SLDData)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 StyledLayer (org.geotools.styling.StyledLayer)1 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)1 Ignore (org.junit.Ignore)1