Search in sources :

Example 56 with StyleWrapper

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

the class GeoServerInputTest method testUpdateLayerStyle.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#updateLayerStyle(com.sldeditor.common.data.StyleWrapper, java.util.List)}.
 */
@Test
public void testUpdateLayerStyle() {
    GeoServerInput input = new GeoServerInput(null);
    GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
    // Add some GeoServer connections
    GeoServerConnection connection1 = new GeoServerConnection();
    connection1.setConnectionName("test connection 1");
    input.addNewConnection(connection1);
    GeoServerConnection connection2 = new GeoServerConnection();
    connection2.setConnectionName("test connection 2");
    input.addNewConnection(connection2);
    // Try with null objects
    input.updateLayerStyle(null);
    // CHECKSTYLE:OFF
    GeoServerLayer[] geoServerLayers = { new GeoServerLayer("workspace", "style1"), new GeoServerLayer("workspace", "style2") };
    // CHECKSTYLE:ON
    List<GeoServerLayer> layerList = Arrays.asList(geoServerLayers);
    StyleWrapper updatedStyle = new StyleWrapper("workspace", "layer1");
    for (GeoServerLayer layer : layerList) {
        layer.setStyle(updatedStyle);
    }
    input.updateLayerStyle(layerList);
}
Also used : GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) StyleWrapper(com.sldeditor.common.data.StyleWrapper) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 57 with StyleWrapper

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

the class GeoServerInputTest method testCopyNodes.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#copyNodes(com.sldeditor.common.NodeInterface, java.util.Map)}.
 */
@Test
public void testCopyNodes() {
    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
    GeoServerWorkspaceNode workspaceTreeNode = new GeoServerWorkspaceNode(input, connection1, "test workspace", false);
    // Create test data
    Map<NodeInterface, List<SLDDataInterface>> copyDataMap = new HashMap<NodeInterface, List<SLDDataInterface>>();
    List<SLDDataInterface> sldToCopyList = new ArrayList<SLDDataInterface>();
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
    SLDData sldData = new SLDData(styleWrapper, "sld contents");
    sldData.setConnectionData(connection1);
    sldToCopyList.add(sldData);
    copyDataMap.put(workspaceTreeNode, sldToCopyList);
    assertFalse(input.copyNodes(workspaceTreeNode, null));
    assertFalse(input.copyNodes(null, copyDataMap));
    // Try with valid parameters
    assertTrue(input.copyNodes(workspaceTreeNode, copyDataMap));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) HashMap(java.util.HashMap) 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) GeoServerWorkspaceNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) ArrayList(java.util.ArrayList) List(java.util.List) NodeInterface(com.sldeditor.common.NodeInterface) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 58 with StyleWrapper

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

the class BatchUpdateFontDataTest method testBatchUpdateFontData.

/**
 * Test method for
 * {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontData#BatchUpdateFontData(org.geotools.styling.StyledLayerDescriptor, com.sldeditor.common.SLDDataInterface)}.
 */
@Test
public void testBatchUpdateFontData() {
    BatchUpdateFontData testObj = new BatchUpdateFontData(null, null);
    assertNull(testObj.getName());
    assertNull(testObj.getWorkspace());
    assertNull(testObj.getSldData());
    String expectedWorkspace = "workspace";
    String expectedStyle = "layer.sld";
    StyleWrapper styleWrapper = new StyleWrapper(expectedWorkspace, expectedStyle);
    SLDData data = new SLDData(styleWrapper, null);
    testObj = new BatchUpdateFontData(null, data);
    assertEquals(testObj.getWorkspace(), expectedWorkspace);
    assertEquals(testObj.getName(), expectedStyle);
    assertEquals(testObj.getSldData(), data);
    String expectedNamedLayer = "namedLayer";
    testObj.setNamedLayer(expectedNamedLayer);
    assertEquals(testObj.getNamedLayer(), expectedNamedLayer);
    String expectedStyleLayer = "style";
    testObj.setStyle(expectedStyleLayer);
    assertEquals(testObj.getStyle(), expectedStyleLayer);
    String expectedFeatureTypeStyleLayer = "feature type style";
    testObj.setFeatureTypeStyle(expectedFeatureTypeStyleLayer);
    assertEquals(testObj.getFeatureTypeStyle(), expectedFeatureTypeStyleLayer);
    assertNull(testObj.getRule());
    assertEquals(testObj.getRuleName(), "");
    assertEquals(testObj.getSymbolizer(), "");
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    String expectedRule = "rule";
    Rule rule = styleFactory.createRule();
    rule.setName(expectedRule);
    testObj.setRule(rule);
    assertEquals(testObj.getRule(), rule);
    assertEquals(testObj.getRuleName(), expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = styleFactory.createTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    testObj.setSymbolizer(symbolizer);
    testObj.setFont(symbolizer.getFont());
    assertEquals(testObj.getSymbolizer(), expectedSymbolizer);
    // Test with font == null
    assertFalse(testObj.isFontNameSet());
    assertFalse(testObj.isFontStyleSet());
    assertFalse(testObj.isFontWeightSet());
    assertFalse(testObj.isFontSizeSet());
    assertEquals(testObj.getFontName(), "");
    assertEquals(testObj.getFontStyle(), "");
    assertEquals(testObj.getFontWeight(), "");
    assertEquals(testObj.getFontSize(), "");
    assertFalse(testObj.anyChanges());
    testObj.revertToOriginal();
    testObj.updateFont((Font) null);
    assertFalse(testObj.updateFont((SLDWriterInterface) null));
    testObj.setFont(null);
    testObj.updateFontSize(45);
    // Set font
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    String originalFontname = "Serif";
    String originalFontStyle = "normal";
    String originalFontWeight = "normal";
    int originalFontSize = 24;
    Font font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
    testObj.setFont(font);
    assertTrue(testObj.isFontNameSet());
    assertTrue(testObj.isFontStyleSet());
    assertTrue(testObj.isFontWeightSet());
    assertTrue(testObj.isFontSizeSet());
    assertFalse(testObj.isFontNameUpdated());
    assertFalse(testObj.isFontStyleUpdated());
    assertFalse(testObj.isFontWeightUpdated());
    assertFalse(testObj.isFontSizeUpdated());
    assertFalse(testObj.anyChanges());
    // Update with a different copy of the same font - no changes
    Font unchangedFont = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
    testObj.updateFont(unchangedFont);
    assertFalse(testObj.isFontNameUpdated());
    assertFalse(testObj.isFontStyleUpdated());
    assertFalse(testObj.isFontWeightUpdated());
    assertFalse(testObj.isFontSizeUpdated());
    // Update with a different copy of the same font - changes
    String expectedFontName = "NewFont";
    String expectedFontStyle = "italic";
    String expectedFontWeight = "bold";
    int expectedFontSize = 12;
    Font changedFont = styleFactory.createFont(ff.literal(expectedFontName), ff.literal(expectedFontStyle), ff.literal(expectedFontWeight), ff.literal(expectedFontSize));
    testObj.updateFont(changedFont);
    assertTrue(testObj.isFontNameUpdated());
    assertTrue(testObj.isFontStyleUpdated());
    assertTrue(testObj.isFontWeightUpdated());
    assertTrue(testObj.isFontSizeUpdated());
    assertTrue(testObj.anyChanges());
    assertEquals(testObj.getFontName(), expectedFontName);
    assertEquals(testObj.getFontStyle(), expectedFontStyle);
    assertEquals(testObj.getFontWeight(), expectedFontWeight);
    assertEquals(testObj.getFontSize(), String.valueOf(expectedFontSize));
    assertEquals(testObj.getFont(), changedFont);
    // Increment font size
    int expectedIncreaseFontSize = 5;
    testObj.updateFontSize(expectedIncreaseFontSize);
    assertEquals(testObj.getFontSize(), String.valueOf(expectedFontSize + expectedIncreaseFontSize));
    // Decrease font size
    expectedIncreaseFontSize *= -1;
    testObj.updateFontSize(expectedIncreaseFontSize);
    assertEquals(testObj.getFontSize(), String.valueOf(expectedFontSize));
    // Try setting the font size less than zero
    expectedIncreaseFontSize = -100;
    testObj.updateFontSize(expectedIncreaseFontSize);
    assertEquals(testObj.getFontSize(), String.valueOf(1));
    // Update font size when font size is a function
    String expectedFieldname = "fieldname";
    changedFont.setSize(ff.property(expectedFieldname));
    testObj.updateFont(changedFont);
    expectedIncreaseFontSize = 5;
    testObj.updateFontSize(expectedIncreaseFontSize);
    String expectedResult = String.format("(%s+%d)", expectedFieldname, expectedIncreaseFontSize);
    String actualResult = testObj.getFontSize();
    assertEquals(actualResult, expectedResult);
    // Revert to original
    testObj.revertToOriginal();
    assertFalse(testObj.isFontNameUpdated());
    assertFalse(testObj.isFontStyleUpdated());
    assertFalse(testObj.isFontWeightUpdated());
    assertFalse(testObj.isFontSizeUpdated());
    assertFalse(testObj.anyChanges());
    assertEquals(testObj.getFontName(), originalFontname);
    assertEquals(testObj.getFontStyle(), originalFontStyle);
    assertEquals(testObj.getFontWeight(), originalFontWeight);
    assertEquals(testObj.getFontSize(), String.valueOf(originalFontSize));
    // Update with the changed font again
    testObj.updateFont(changedFont);
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    symbolizer.fonts().add(changedFont);
    assertFalse(testObj.updateFont(sldWriter));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) TextSymbolizer(org.geotools.styling.TextSymbolizer) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Rule(org.geotools.styling.Rule) BatchUpdateFontData(com.sldeditor.tool.batchupdatefont.BatchUpdateFontData) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Test(org.junit.Test)

Example 59 with StyleWrapper

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

the class BatchUpdateFontUtilsTest method testContainsFonts.

/**
 * Test method for {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontUtils#containsFonts(com.sldeditor.common.SLDDataInterface)}.
 */
@Test
public void testContainsFonts() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    String expectedNameLayerValue = "named layer test value";
    namedLayer.setName(expectedNameLayerValue);
    Style style = DefaultSymbols.createNewStyle();
    String expectedNameStyleValue = "style test value";
    style.setName(expectedNameStyleValue);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedNameFTSValue = "feature type style test value";
    fts.setName(expectedNameFTSValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedRuleValue = "rule test value";
    rule.setName(expectedRuleValue);
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    rule.symbolizers().add(DefaultSymbols.createDefaultPointSymbolizer());
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    String sldContents = sldWriter.encodeSLD(null, sld);
    SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), sldContents);
    // Empty sld
    List<BatchUpdateFontData> actualList = BatchUpdateFontUtils.containsFonts(null);
    assertNull(actualList);
    // No fonts
    actualList = BatchUpdateFontUtils.containsFonts(sldData);
    assertNull(actualList);
    // With textsymbolizer
    rule.symbolizers().add(symbolizer);
    sldContents = sldWriter.encodeSLD(null, sld);
    sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), sldContents);
    actualList = BatchUpdateFontUtils.containsFonts(sldData);
    assertEquals(1, actualList.size());
    assertEquals(rule.getName(), actualList.get(0).getRuleName());
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleWrapper(com.sldeditor.common.data.StyleWrapper) 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) 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