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());
}
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());
}
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());
}
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));
}
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()));
}
Aggregations