Search in sources :

Example 66 with SLDData

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

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

use of com.sldeditor.common.data.SLDData 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

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