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