[Schmitzm-commits] r1153 - in trunk/src_junit: schmitzm/geotools/styling schmitzm/jfree/feature/style schmitzm/swing skrueger/i8n

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 20 10:39:37 CEST 2010


Author: alfonx
Date: 2010-10-20 10:39:36 +0200 (Wed, 20 Oct 2010)
New Revision: 1153

Modified:
   trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
   trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
   trunk/src_junit/schmitzm/swing/TestingUtil.java
   trunk/src_junit/skrueger/i8n/TranslationTest.java
Log:
Simplified TestingUtil testdataset methods

Modified: trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-10-18 15:11:35 UTC (rev 1152)
+++ trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-10-20 08:39:36 UTC (rev 1153)
@@ -54,8 +54,7 @@
 	@Test
 	public void testSelectionStyles() throws Throwable {
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise.getFeatureCollection();
 
 		JPanel jPanel = new JPanel();
 

Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-10-18 15:11:35 UTC (rev 1152)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-10-20 08:39:36 UTC (rev 1153)
@@ -58,8 +58,8 @@
 	@Test
 	public void testChartStyleCopyToWithScatterChartStyle() throws Throwable {
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 		FeatureChartStyle style1 = new FeatureScatterChartStyle("1");
 		style1.setAttributeName(0, "jahr");
 		style1.setAttributeName(1, "w_bev");
@@ -79,8 +79,8 @@
 	@Test
 	public void testChartStyleCopyToWithBasicChartStyle() throws Throwable {
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 		FeatureChartStyle style1 = new FeatureBasicChartStyle("1",
 				ChartType.BAR);
 		style1.setAttributeName(0, "jahr");
@@ -99,60 +99,58 @@
 		TestingUtil.testGui(chart, "barchart");
 	}
 
-	
 	@Test
 	public void testAutomaticAdjustmentsOnDualAxes() throws Throwable {
-      ChartAxisStyle domainAxisStyle = new ChartAxisStyle("jahreszahlen",
-          Color.red, 0., 0.);
-      ChartAxisStyle rangeAxisStyle = new ChartAxisStyle("deut. maenner",
-          Color.green, 0., 0.);
-      ChartAxisStyle rangeAxisStyle2 = new ChartAxisStyle(
-          "Weibl. Bevölkerung", Color.blue, 0., 0.);
+		ChartAxisStyle domainAxisStyle = new ChartAxisStyle("jahreszahlen",
+				Color.red, 0., 0.);
+		ChartAxisStyle rangeAxisStyle = new ChartAxisStyle("deut. maenner",
+				Color.green, 0., 0.);
+		ChartAxisStyle rangeAxisStyle2 = new ChartAxisStyle(
+				"Weibl. Bevölkerung", Color.blue, 0., 0.);
 
-      BasicChartStyle barChartStyle = new BasicChartStyle(
-              "testBarChartWith2Axis", ChartType.BAR);
-    
-      barChartStyle.setAxisStyle(0, domainAxisStyle);
-      barChartStyle.setAxisStyle(1, rangeAxisStyle);
-      barChartStyle.setAxisStyle(2, rangeAxisStyle2);
-    
-      assertNull("Wenn nicht explizit gesetzt wird null geliefert",
-              barChartStyle.getRendererStyle(0));
+		BasicChartStyle barChartStyle = new BasicChartStyle(
+				"testBarChartWith2Axis", ChartType.BAR);
 
-      ChartRendererStyle chartRendererStyle = new ChartRendererStyle();
-      chartRendererStyle.setDefaultPaint(Color.blue);
-      chartRendererStyle.setSeriesPaint(0, Color.green);
-      chartRendererStyle.setSeriesPaint(1, Color.red);
-      chartRendererStyle.setSeriesPaint(2, Color.GRAY);
-      barChartStyle.setRendererStyle(0, chartRendererStyle);
-      assertEquals(3, chartRendererStyle.getSeriesCount());
+		barChartStyle.setAxisStyle(0, domainAxisStyle);
+		barChartStyle.setAxisStyle(1, rangeAxisStyle);
+		barChartStyle.setAxisStyle(2, rangeAxisStyle2);
 
-      // Renderer style for the series dealing with the
-      // secondary axis.
-      ChartRendererStyle chartRendererStyle2 = new ChartRendererStyle();
-      chartRendererStyle2.setDefaultLineDashAttributes(5.0f, 5.0f);
-      chartRendererStyle2.setSeriesLineWidth(1, 10);
-      chartRendererStyle2.setSeriesLineDashAttributes(1, 10f, 10f);
-      barChartStyle.setRendererStyle(1, chartRendererStyle2);
+		assertNull("Wenn nicht explizit gesetzt wird null geliefert",
+				barChartStyle.getRendererStyle(0));
 
-      CategoryDataset data1 = createSampleCategoryDataset1(true,1);
-      CategoryDataset data2 = createSampleCategoryDataset2(true,-1);
+		ChartRendererStyle chartRendererStyle = new ChartRendererStyle();
+		chartRendererStyle.setDefaultPaint(Color.blue);
+		chartRendererStyle.setSeriesPaint(0, Color.green);
+		chartRendererStyle.setSeriesPaint(1, Color.red);
+		chartRendererStyle.setSeriesPaint(2, Color.GRAY);
+		barChartStyle.setRendererStyle(0, chartRendererStyle);
+		assertEquals(3, chartRendererStyle.getSeriesCount());
 
-      JFreeChart barChart = barChartStyle.applyToDataset(data1, data2);
-      JFreeChartUtil.resetRangeAxisTickLabelVisibiliy(barChart);
+		// Renderer style for the series dealing with the
+		// secondary axis.
+		ChartRendererStyle chartRendererStyle2 = new ChartRendererStyle();
+		chartRendererStyle2.setDefaultLineDashAttributes(5.0f, 5.0f);
+		chartRendererStyle2.setSeriesLineWidth(1, 10);
+		chartRendererStyle2.setSeriesLineDashAttributes(1, 10f, 10f);
+		barChartStyle.setRendererStyle(1, chartRendererStyle2);
 
-      assertNotNull("applyToDataset lieferte null!", barChart);
+		CategoryDataset data1 = createSampleCategoryDataset1(true, 1);
+		CategoryDataset data2 = createSampleCategoryDataset2(true, -1);
 
-      TestingUtil.testGui(barChart, "bar chart",-1);
+		JFreeChart barChart = barChartStyle.applyToDataset(data1, data2);
+		JFreeChartUtil.resetRangeAxisTickLabelVisibiliy(barChart);
+
+		assertNotNull("applyToDataset lieferte null!", barChart);
+
+		TestingUtil.testGui(barChart, "bar chart", -1);
 	}
 
-	
 	@Ignore
 	@Test
 	public void testLineChartDualAxis() throws Throwable {
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 
 		// Daten auf korrektheit überprüfen
 		String groupAttribName = "code"; // KreisZahl
@@ -229,10 +227,11 @@
 	 * frames etc.
 	 **/
 
-	public CategoryDataset createSampleCategoryDataset1(boolean nullSecondary, int valuesType) {
+	public CategoryDataset createSampleCategoryDataset1(boolean nullSecondary,
+			int valuesType) {
 		// row keys...
 		String series1 = "Series 1";
-		String series2 = JFreeChartUtil.DUMMY_SERIES_PREFIX+"1";
+		String series2 = JFreeChartUtil.DUMMY_SERIES_PREFIX + "1";
 
 		// column keys...
 		String category1 = "Category 1";
@@ -243,14 +242,14 @@
 		// create the dataset...
 		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
 
-        // ValuesType 0 means an empty dataset
-        if ( valuesType != 0 ) {
-    		dataset.addValue(1.0 * valuesType, series1, category1);
-    		dataset.addValue(4.0 * valuesType, series1, category2);
-    		dataset.addValue(3.0 * valuesType, series1, category3);
-    		dataset.addValue(5.0 * valuesType, series1, category4);
-        }
-        
+		// ValuesType 0 means an empty dataset
+		if (valuesType != 0) {
+			dataset.addValue(1.0 * valuesType, series1, category1);
+			dataset.addValue(4.0 * valuesType, series1, category2);
+			dataset.addValue(3.0 * valuesType, series1, category3);
+			dataset.addValue(5.0 * valuesType, series1, category4);
+		}
+
 		if (nullSecondary && valuesType != 0) {
 			dataset.addValue(null, series2, category1);
 			dataset.addValue(null, series2, category2);
@@ -260,9 +259,10 @@
 		return dataset;
 	}
 
-	public CategoryDataset createSampleCategoryDataset2(boolean nullPrimary, int valuesType) {
+	public CategoryDataset createSampleCategoryDataset2(boolean nullPrimary,
+			int valuesType) {
 		// row keys...
-		String series1 = JFreeChartUtil.DUMMY_SERIES_PREFIX+"2";
+		String series1 = JFreeChartUtil.DUMMY_SERIES_PREFIX + "2";
 		String series2 = "Series 2";
 
 		// column keys...
@@ -274,7 +274,7 @@
 		// create the dataset...
 		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
 
-        // ValuesType 0 means an empty dataset
+		// ValuesType 0 means an empty dataset
 		if (nullPrimary && valuesType != 0) {
 			dataset.addValue(null, series1, category1);
 			dataset.addValue(null, series1, category2);
@@ -282,18 +282,18 @@
 			dataset.addValue(null, series1, category4);
 		}
 
-        // ValuesType 0 means an empty dataset
-        if ( valuesType != 0 ) {
-          dataset.addValue(75.0 * valuesType, series2, category1);
-          dataset.addValue(87.0 * valuesType, series2, category2);
-          dataset.addValue(96.0 * valuesType, series2, category3);
-          dataset.addValue(68.0 * valuesType, series2, category4);
-        }
-        return dataset;
+		// ValuesType 0 means an empty dataset
+		if (valuesType != 0) {
+			dataset.addValue(75.0 * valuesType, series2, category1);
+			dataset.addValue(87.0 * valuesType, series2, category2);
+			dataset.addValue(96.0 * valuesType, series2, category3);
+			dataset.addValue(68.0 * valuesType, series2, category4);
+		}
+		return dataset;
 
 	}
 
-    @Test
+	@Test
 	@Ignore
 	public void testBarChartDualAxisWithSampleData() throws Throwable {
 		ChartAxisStyle domainAxisStyle = new ChartAxisStyle("jahreszahlen",
@@ -329,8 +329,8 @@
 		chartRendererStyle2.setSeriesLineDashAttributes(1, 10f, 10f);
 		barChartStyle.setRendererStyle(1, chartRendererStyle2);
 
-		CategoryDataset data1 = createSampleCategoryDataset1(true,1);
-		CategoryDataset data2 = createSampleCategoryDataset2(true,1);
+		CategoryDataset data1 = createSampleCategoryDataset1(true, 1);
+		CategoryDataset data2 = createSampleCategoryDataset2(true, 1);
 
 		JFreeChart barChart = barChartStyle.applyToDataset(data1, data2);
 		assertNotNull("applyToDataset lieferte null!", barChart);
@@ -370,8 +370,8 @@
 		String yAxisAttName2 = "w_bev";
 		String groupAttName = "jahr";
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> features = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> features = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 
 		log.info("BarChart für " + features.size() + " Features wird erstellt");
 
@@ -454,8 +454,8 @@
 	// @Ignore
 	public void testBarChartDualAxis() throws Throwable {
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 
 		// Daten auf korrektheit überprüfen
 		String groupAttribName = "code"; // KreisZahl
@@ -554,8 +554,8 @@
 	@Test
 	public void testBarChartSortedSeries() throws Throwable {
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 
 		// Daten auf korrektheit überprüfen
 		String groupAttribName = "jahr"; // KreisZahl
@@ -659,8 +659,8 @@
 	public void testBarChartForcedCategories() throws Throwable {
 
 		// Testdatenshape einlesen
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 
 		// Daten auf korrektheit überprüfen
 		assertEquals("Testfeatures muss 3x3 Features enthalten", 3 * 3,
@@ -724,8 +724,8 @@
 	@Test
 	public void testLineChartAsCategories() throws Throwable {
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 
 		// Daten auf korrektheit überprüfen
 		String groupAttribName = "code"; // KreisZahl
@@ -797,8 +797,7 @@
 				"test line chart: soll nur line 06533 existieren!");
 
 		File testFile = File.createTempFile("testLineChart", ".xml");
-		
-		
+
 		xmlFactoryFeature.writeStyleToFile(lineChartStyle, "testLineChart",
 				testFile);
 		assertTrue(testFile.getAbsolutePath() + " wurde nicht geschrieben!",
@@ -832,8 +831,8 @@
 	@Test
 	public void testLineChartNOTCategories() throws Throwable {
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
-				.getTestFeatures();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 
 		// Daten auf korrektheit überprüfen
 		String groupAttribName = "code"; // KreisZahl

Modified: trunk/src_junit/schmitzm/swing/TestingUtil.java
===================================================================
--- trunk/src_junit/schmitzm/swing/TestingUtil.java	2010-10-18 15:11:35 UTC (rev 1152)
+++ trunk/src_junit/schmitzm/swing/TestingUtil.java	2010-10-20 08:39:36 UTC (rev 1153)
@@ -26,6 +26,7 @@
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 
+import org.geotools.data.DataStore;
 import org.geotools.data.DataUtilities;
 import org.geotools.data.FeatureSource;
 import org.geotools.data.shapefile.ShapefileDataStore;
@@ -44,6 +45,7 @@
 import schmitzm.io.IOUtil;
 import schmitzm.jfree.feature.style.FeatureChartStyle;
 import schmitzm.lang.LangUtil;
+import skrueger.geotools.io.GeoImportUtilURL;
 
 /**
  * Helpers to test Swing applications in general. <br/>
@@ -58,18 +60,40 @@
 	 * List of available test datasets
 	 */
 	public static enum TestDatasets {
-		arabicInHeader, kreise;
+		arabicInHeader(
+				"/schmitzm/geotools/feature/arabicShapefiles/arabicwitharabicinheader.shp"), kreise(
+				"/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp");
 
+		private final String resLoc;
+
+		private TestDatasets(String resLoc) {
+			this.resLoc = resLoc;
+		}
+
+		public String getResLoc() {
+			return resLoc;
+		}
+
 		public URL getUrl() {
-			switch (this) {
-			case kreise:
-				return TestingUtil.class.getResource(resLocation_Kreise);
-			case arabicInHeader:
-				return TestingUtil.class.getResource(resLocation_ArabicHeader);
+			return TestingUtil.class.getResource(getResLoc());
+		}
 
-			}
-			return null;
+		public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource()
+				throws IOException {
+			DataStore ds = getDataStore();
+			return ds.getFeatureSource(ds.getTypeNames()[0]);
 		}
+
+		public DataStore getDataStore() throws IOException {
+			DataStore ds = GeoImportUtilURL.readDataStoreFromShape(getUrl(),
+					null);
+			return ds;
+		}
+
+		public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection()
+				throws IOException {
+			return getFeatureSource().getFeatures();
+		}
 	}
 
 	/**
@@ -77,10 +101,7 @@
 	 * system is not running in headless mode.
 	 */
 	public static final boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
-	final static String resLocation_ArabicHeader = "/schmitzm/geotools/feature/arabicShapefiles/arabicwitharabicinheader.shp";
 
-	final static String resLocation_Kreise = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp";
-
 	/**
 	 * Number of seconds to wait until a GUI should be closed by default. Can be
 	 * set to -1 to always wait forever.
@@ -210,52 +231,18 @@
 	}
 
 	/**
-	 * Stellt Test-Features zur Verfügung, WENN die Anwendung im maven scope
-	 * <code>test</code> läuft.
-	 * 
-	 * @deprecated use getTestFeatures(ENUM TestData)
-	 */
-	public static FeatureCollection<SimpleFeatureType, SimpleFeature> getTestFeatures()
-			throws IOException {
-		// Testdatenshape einlesen
-		URL resourceUrl = FeatureChartStyle.class
-				.getResource(resLocation_Kreise);
-
-		if (resourceUrl == null)
-			throw new IllegalStateException(resLocation_Kreise
-					+ " wurde nicht gefunden!");
-
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = GeoImportUtil
-				.readFeaturesFromShapeURL(resourceUrl);
-
-		if (testFeatures == null)
-			throw new IllegalStateException(
-					"Testfeatures konnten nicht gelesen werden");
-
-		return testFeatures;
-	}
-
-	/**
 	 * Stellt Test-FeatureCollections zur Verfügung
 	 */
-	public static FeatureCollection<SimpleFeatureType, SimpleFeature> getTestFeatures(
-			TestDatasets dataset) throws IOException {
-		return getTestFeatureSource(dataset).getFeatures();
-	}
-
-	/**
-	 * Stellt Test-FeatureCollections zur Verfügung
-	 */
 	public static FeatureSource<SimpleFeatureType, SimpleFeature> getTestFeatureSource(
 			TestDatasets dataset) throws IOException {
 		// Testdatenshape einlesen
-		URL resourceUrl = dataset.getUrl();
+		// URL resourceUrl = dataset.getUrl();
+		//
+		// if (resourceUrl == null)
+		// throw new IllegalStateException(dataset + " wurde nicht gefunden!");
 
-		if (resourceUrl == null)
-			throw new IllegalStateException(dataset + " wurde nicht gefunden!");
+		ShapefileDataStore store = (ShapefileDataStore) dataset.getDataStore();
 
-		ShapefileDataStore store = new ShapefileDataStore(resourceUrl);
-
 		if (dataset == TestDatasets.arabicInHeader) {
 			// TODO overthink
 			store.setStringCharset(Charset.forName("windows-1256"));

Modified: trunk/src_junit/skrueger/i8n/TranslationTest.java
===================================================================
--- trunk/src_junit/skrueger/i8n/TranslationTest.java	2010-10-18 15:11:35 UTC (rev 1152)
+++ trunk/src_junit/skrueger/i8n/TranslationTest.java	2010-10-20 08:39:36 UTC (rev 1153)
@@ -97,7 +97,7 @@
 		calledC.set(false);
 		Translation.setActiveLang("de");
 		Translation.setActiveLang("en");
-		
+
 		assertTrue(calledAl.get());
 		assertTrue(calledL.get());
 		assertFalse(calledC.get());
@@ -130,4 +130,12 @@
 		Translation.setActiveLang("ru");
 		assertEquals("ru", t.toString());
 	}
+
+	@Test
+	public void testFromOneLine() {
+		Translation t = new Translation();
+		t.fromOneLine("en{- 3 MBps/billion capita}");
+
+		assertEquals("- 3 MBps/billion capita", t.toString("en"));
+	}
 }



More information about the Schmitzm-commits mailing list