/** * OrbisGIS is a java GIS application dedicated to research in GIScience. * OrbisGIS is developed by the GIS group of the DECIDE team of the * Lab-STICC CNRS laboratory, see <http://www.lab-sticc.fr/>. * * The GIS group of the DECIDE team is located at : * * Laboratoire Lab-STICC – CNRS UMR 6285 * Equipe DECIDE * UNIVERSITÉ DE BRETAGNE-SUD * Institut Universitaire de Technologie de Vannes * 8, Rue Montaigne - BP 561 56017 Vannes Cedex * * OrbisGIS is distributed under GPL 3 license. * * Copyright (C) 2007-2014 CNRS (IRSTV FR CNRS 2488) * Copyright (C) 2015-2017 CNRS (Lab-STICC UMR CNRS 6285) * * This file is part of OrbisGIS. * * OrbisGIS is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * OrbisGIS is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * OrbisGIS. If not, see <http://www.gnu.org/licenses/>. * * For more information, please consult: <http://www.orbisgis.org/> * or contact directly: * info_at_ orbisgis.org */ package org.orbisgis.legend.analyzer; import java.awt.Color; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Test; import org.orbisgis.coremap.renderer.se.LineSymbolizer; import org.orbisgis.coremap.renderer.se.Style; import org.orbisgis.coremap.renderer.se.common.Uom; import org.orbisgis.coremap.renderer.se.fill.SolidFill; import org.orbisgis.coremap.renderer.se.parameter.real.Interpolate2Real; import org.orbisgis.coremap.renderer.se.parameter.real.RealLiteral; import org.orbisgis.coremap.renderer.se.parameter.real.RealParameter; import org.orbisgis.coremap.renderer.se.parameter.string.StringLiteral; import org.orbisgis.coremap.renderer.se.stroke.PenStroke; import org.orbisgis.legend.AnalyzerTest; import org.orbisgis.legend.analyzer.symbolizers.LineSymbolizerAnalyzer; import org.orbisgis.legend.thematic.LineParameters; import org.orbisgis.legend.thematic.categorize.CategorizedLine; import org.orbisgis.legend.thematic.constant.UniqueSymbolLine; import org.orbisgis.legend.thematic.proportional.ProportionalLine; /** * Test that we recognize known configurations for LineSymbolizer instances. * @author Alexis Guéganno */ public class LineSymbolizerAnalyzerTest extends AnalyzerTest { /**************************************************************************/ /* Let's test the constant lines. We will try to retrieve each of the */ /* possible parameters, including dashes. There will be two cases, both */ /* made with a PenStroke. One used a DashArray in its definition, but the */ /* other does not. */ /**************************************************************************/ @Test public void testInitializationUniqueSymbol() throws Exception { UniqueSymbolLine usl = getUniqueSymbolLine(CONSTANT_LINE); assertTrue(true); } @Test public void testAnalyzerUniqueSymbol() throws Exception { Style st = getStyle(CONSTANT_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); LineSymbolizerAnalyzer lsa = new LineSymbolizerAnalyzer(ls); assertTrue(lsa.getLegend() instanceof UniqueSymbolLine); } @Test public void testAnalyzerUniqueSymbolDash() throws Exception { Style st = getStyle(CONSTANT_DASHED_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); LineSymbolizerAnalyzer lsa = new LineSymbolizerAnalyzer(ls); assertTrue(lsa.getLegend() instanceof UniqueSymbolLine); } @Test public void testInitializationFailUniqueSymbol() throws Exception { Style st = getStyle(PROP_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); try{ UniqueSymbolLine usl = new UniqueSymbolLine(ls); fail(); } catch (ClassCastException iae){ assertTrue(true); } } @Test public void testGetUniqueValueColor() throws Exception{ UniqueSymbolLine usl = getUniqueSymbolLine(CONSTANT_LINE); Color col = usl.getLineColor(); assertTrue(col.equals(new Color((int)SolidFill.GRAY50,(int)SolidFill.GRAY50,(int)SolidFill.GRAY50))); } @Test public void testSetUniqueValueColor() throws Exception{ UniqueSymbolLine usl = getUniqueSymbolLine(CONSTANT_LINE); usl.setLineColor(Color.BLUE); assertTrue(usl.getLineColor().equals(Color.BLUE)); } @Test public void testGetUniqueValueWidth() throws Exception{ UniqueSymbolLine usl = getUniqueSymbolLine(CONSTANT_LINE); assertTrue(usl.getPenStroke().getLineWidth() == 8.0); } @Test public void testSetUniqueValueWidth() throws Exception{ UniqueSymbolLine usl = getUniqueSymbolLine(CONSTANT_LINE); usl.getPenStroke().setLineWidth(15.0); assertTrue(usl.getPenStroke().getLineWidth() == 15.0); } @Test public void testUniqueValueGetDash() throws Exception { UniqueSymbolLine usl = getUniqueSymbolLine(CONSTANT_DASHED_LINE); assertTrue(usl.getPenStroke().getDashArray().equals("1 2 1 3")); } @Test public void testUniqueValueSetDash() throws Exception { Style st = getStyle(CONSTANT_DASHED_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); UniqueSymbolLine usl = new UniqueSymbolLine(ls); usl.getPenStroke().setDashArray("1 5 3"); assertTrue(usl.getPenStroke().getDashArray().equals("1 5 3")); } @Test public void testUniqueValueRemoveDash() throws Exception { Style st = getStyle(CONSTANT_DASHED_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); UniqueSymbolLine usl = new UniqueSymbolLine(ls); usl.getPenStroke().setDashArray(""); PenStroke ps = (PenStroke) ls.getStroke(); StringLiteral sl = (StringLiteral) ps.getDashArray(); assertTrue(sl.getValue(null).isEmpty()); assertTrue(usl.getPenStroke().getDashArray().equals("")); } @Test public void testUniqueValueAddDash() throws Exception { Style st = getStyle(CONSTANT_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); UniqueSymbolLine usl = new UniqueSymbolLine(ls); PenStroke ps = (PenStroke) ls.getStroke(); StringLiteral sl = (StringLiteral) ps.getDashArray(); assertTrue(sl.getValue(null).isEmpty()); assertTrue(usl.getPenStroke().getDashArray().equals("")); usl.getPenStroke().setDashArray("1 5 3"); assertTrue(usl.getPenStroke().getDashArray().equals("1 5 3")); } @Test public void testUniqueValueAddWrongDash() throws Exception { Style st = getStyle(CONSTANT_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); UniqueSymbolLine usl = new UniqueSymbolLine(ls); PenStroke ps = (PenStroke) ls.getStroke(); StringLiteral sl = (StringLiteral) ps.getDashArray(); assertTrue(sl.getValue(null).isEmpty()); assertTrue(usl.getPenStroke().getDashArray().equals("")); usl.getPenStroke().setDashArray("bonjour bonjour !"); assertTrue(sl.getValue(null).isEmpty()); assertTrue(usl.getPenStroke().getDashArray().equals("")); } @Test public void testUniqueValueSetWrongDash() throws Exception { Style st = getStyle(CONSTANT_DASHED_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); UniqueSymbolLine usl = new UniqueSymbolLine(ls); usl.getPenStroke().setDashArray("bonjour bonjour !"); PenStroke ps = (PenStroke) ls.getStroke(); StringLiteral sl = (StringLiteral) ps.getDashArray(); assertTrue(sl.getValue(null).isEmpty()); assertTrue(usl.getPenStroke().getDashArray().equals("")); } @Test public void testUniqueValueSetWrongDashBis() throws Exception { Style st = getStyle(CONSTANT_DASHED_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); UniqueSymbolLine usl = new UniqueSymbolLine(ls); usl.getPenStroke().setDashArray("1 -5 3"); assertTrue(usl.getPenStroke().getDashArray().equals("")); } @Test public void testDefaultConstructorUniqueSymbol() throws Exception { UniqueSymbolLine usl = new UniqueSymbolLine(); LineSymbolizerAnalyzer lsa = new LineSymbolizerAnalyzer((LineSymbolizer)usl.getSymbolizer()); assertTrue(lsa.getLegend() instanceof UniqueSymbolLine); assertTrue(usl.getPenStroke().getLineWidth() == PenStroke.DEFAULT_WIDTH); assertTrue(usl.getLineColor().equals(Color.BLACK)); } @Test public void testGetUom() throws Exception { Style st = getStyle(PROP_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); ProportionalLine usl = new ProportionalLine(ls); assertTrue(usl.getStrokeUom() == Uom.MM); } @Test public void testSetUom() throws Exception { Style st = getStyle(PROP_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); ProportionalLine usl = new ProportionalLine(ls); assertTrue(usl.getStrokeUom() == Uom.MM); usl.setStrokeUom(Uom.IN); assertTrue(usl.getStrokeUom() == Uom.IN); usl.setStrokeUom(null); assertTrue(usl.getStrokeUom() == Uom.MM); } @Test public void testInterpolateValidation() throws Exception { Style st = getStyle(PROP_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); LineSymbolizerAnalyzer lsa = new LineSymbolizerAnalyzer(new LineSymbolizer()); RealParameter rp= ((PenStroke)ls.getStroke()).getWidth(); assertTrue(lsa.validateLinearInterpolate(rp)); } @Test public void testInterpolateValidation2() throws Exception { Style st = getStyle(PROP_LINE); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); LineSymbolizerAnalyzer lsa = new LineSymbolizerAnalyzer(new LineSymbolizer()); Interpolate2Real rp= (Interpolate2Real) ((PenStroke)ls.getStroke()).getWidth(); rp.setLookupValue(new RealLiteral(2.0)); assertFalse(lsa.validateLinearInterpolate(rp)); } @Test public void testGetLineParams() throws Exception { UniqueSymbolLine usl = getUniqueSymbolLine(CONSTANT_LINE); LineParameters lp = usl.getLineParameters(); assertTrue(lp.equals(new LineParameters(new Color((int)SolidFill.GRAY50,(int)SolidFill.GRAY50,(int)SolidFill.GRAY50), 1.0,8.0,""))); } @Test public void testFromLineParams() throws Exception { UniqueSymbolLine usl = new UniqueSymbolLine(new LineParameters(Color.BLUE, .5, 2.6, "2 2 2 5")); assertTrue(usl.getPenStroke().getDashArray().equals("2 2 2 5")); assertTrue(usl.getPenStroke().getLineOpacity() == .5); assertTrue(usl.getPenStroke().getLineWidth() == 2.6); assertTrue(usl.getPenStroke().getLineColor().equals(Color.BLUE)); } @Test public void testFindCategorizedLine() throws Exception { Style st = getStyle(CATEGORIZED_LINE); LineSymbolizer ls = (LineSymbolizer) st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); LineSymbolizerAnalyzer lsa = new LineSymbolizerAnalyzer(ls); assertTrue(lsa.getLegend() instanceof CategorizedLine); } private UniqueSymbolLine getUniqueSymbolLine(String s) throws Exception { Style st = getStyle(s); LineSymbolizer ls = (LineSymbolizer)st.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0); return new UniqueSymbolLine(ls); } }