Search in sources :

Example 26 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper 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 27 with StyleWrapper

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

the class MapBoxFileHandlerTest method testGetSLDName.

/**
 * Test method for {@link com.sldeditor.extension.filesystem.file.mapbox.MapBoxFileHandler#getSLDName(com.sldeditor.common.SLDDataInterface)}.
 */
@Test
public void testGetSLDName() {
    MapBoxFileHandler handler = new MapBoxFileHandler();
    assertTrue(handler.getSLDName(null).compareTo("") == 0);
    SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), "sldContents");
    String sldName = handler.getSLDName(sldData);
    assertTrue(sldName.compareTo("layer.json") == 0);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) MapBoxFileHandler(com.sldeditor.extension.filesystem.file.mapbox.MapBoxFileHandler) Test(org.junit.Test)

Example 28 with StyleWrapper

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

the class RasterFileHandlerTest method testGetSLDName.

/**
 * Supply a folder name and retrieve all the sld files in it
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.raster.RasterFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDName() {
    RasterFileHandler handler = new RasterFileHandler();
    assertTrue(handler.getSLDName(null).compareTo("") == 0);
    SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), "sldContents");
    String sldName = handler.getSLDName(sldData);
    assertTrue(sldName.compareTo("layer.sld") == 0);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) RasterFileHandler(com.sldeditor.extension.filesystem.file.raster.RasterFileHandler) Test(org.junit.Test)

Example 29 with StyleWrapper

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

the class VectorFileHandlerTest method testGetSLDName.

/**
 * Supply a folder name and retrieve all the sld files in it
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.vector.VectorFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDName() {
    VectorFileHandler handler = new VectorFileHandler();
    assertTrue(handler.getSLDName(null).compareTo("") == 0);
    SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), "sldContents");
    String sldName = handler.getSLDName(sldData);
    assertTrue(sldName.compareTo("layer.sld") == 0);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) VectorFileHandler(com.sldeditor.extension.filesystem.file.vector.VectorFileHandler) Test(org.junit.Test)

Example 30 with StyleWrapper

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

the class BatchUpdateFontModelTest method testLoadData.

/**
 * Test method for {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel#loadData(java.util.List)}.
 */
@Test
public void testLoadData() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    String sldContents = sldWriter.encodeSLD(null, sld);
    String expectedWorkspace = "workspace";
    String expectedStyle = "layer.sld";
    StyleWrapper styleWrapper = new StyleWrapper(expectedWorkspace, expectedStyle);
    SLDData data = new SLDData(styleWrapper, sldContents);
    File testFile = new File("test.sld");
    data.setSLDFile(testFile);
    SLDEditorFile.getInstance().setSldFile(testFile);
    SLDEditorFile.getInstance().setSLDData(data);
    BatchUpdateFontData testObj = new BatchUpdateFontData(sld, data);
    SelectedSymbol.getInstance().setSld(sld);
    testObj.setNamedLayer(expectedNamedLayer);
    testObj.setStyle(expectedStyleLayer);
    testObj.setFeatureTypeStyle(expectedFeatureTypeStyleLayer);
    testObj.setRule(rule);
    testObj.setSymbolizer(symbolizer);
    testObj.setFont(font);
    List<BatchUpdateFontData> dataList = new ArrayList<BatchUpdateFontData>();
    dataList.add(testObj);
    BatchUpdateFontModel model = new BatchUpdateFontModel();
    model.loadData(dataList);
    for (int col = 0; col < model.getColumnCount(); col++) {
        assertFalse(model.hasValueBeenUpdated(0, col));
    }
    assertFalse(model.anyChanges());
    assertFalse(model.saveData(null));
    List<Font> actualFontlist = model.getFontEntries(new int[] { 0 });
    assertEquals(1, actualFontlist.size());
    assertEquals(1, model.getRowCount());
    // Update font
    String originalFontname = "New Font";
    String originalFontStyle = "italic";
    String originalFontWeight = "bold";
    int originalFontSize = 16;
    font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
    model.applyData(new int[] { 0 }, font);
    assertTrue(model.hasValueBeenUpdated(0, 7));
    assertTrue(model.hasValueBeenUpdated(0, 8));
    assertTrue(model.hasValueBeenUpdated(0, 9));
    assertTrue(model.hasValueBeenUpdated(0, 10));
    assertTrue(model.anyChanges());
    assertEquals(originalFontname, model.getValueAt(0, 7));
    assertEquals(originalFontStyle, model.getValueAt(0, 8));
    assertEquals(originalFontWeight, model.getValueAt(0, 9));
    assertEquals(String.valueOf(originalFontSize), model.getValueAt(0, 10));
    model.revertData();
    assertFalse(model.anyChanges());
    int expectedFontSize = 99;
    model.applyData(new int[] { 0 }, expectedFontSize);
    // Font size
    assertTrue(model.hasValueBeenUpdated(0, 10));
    assertEquals(expectedWorkspace, model.getValueAt(0, 0));
    assertEquals(expectedStyle, model.getValueAt(0, 1));
    assertEquals(expectedNamedLayer, model.getValueAt(0, 2));
    assertEquals(expectedStyleLayer, model.getValueAt(0, 3));
    assertEquals(expectedFeatureTypeStyleLayer, model.getValueAt(0, 4));
    assertEquals(expectedRule, model.getValueAt(0, 5));
    assertEquals(expectedSymbolizer, model.getValueAt(0, 6));
    assertEquals("abc", model.getValueAt(0, 7));
    assertEquals("normal", model.getValueAt(0, 8));
    assertEquals("normal", model.getValueAt(0, 9));
    assertEquals(String.valueOf(10 + expectedFontSize), model.getValueAt(0, 10));
    assertNull(model.getValueAt(0, 42));
    assertTrue(model.saveData(null));
    SelectedSymbol.destroyInstance();
    SLDEditorFile.destroyInstance();
    model.setColumnRenderer(null);
    JTable table = new JTable();
    table.setModel(model);
    model.setColumnRenderer(table.getColumnModel());
    assertFalse(model.isCellEditable(0, 0));
    assertEquals(Localisation.getString(BatchUpdateFontModel.class, "BatchUpdateFontModel.workspace"), model.getColumnName(0));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) ArrayList(java.util.ArrayList) BatchUpdateFontModel(com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) StyleWrapper(com.sldeditor.common.data.StyleWrapper) JTable(javax.swing.JTable) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Rule(org.geotools.styling.Rule) BatchUpdateFontData(com.sldeditor.tool.batchupdatefont.BatchUpdateFontData) NamedLayer(org.geotools.styling.NamedLayer) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.Test)

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