[Schmitzm-commits] r1409 - in trunk/schmitzm-core: . src/main/java/de/schmitzm src/main/java/de/schmitzm/net src/test/java/de/schmitzm src/test/java/de/schmitzm/io src/test/java/de/schmitzm/net src/test/java/de/schmitzm/swing src/test/java/de/schmitzm/swing/swingworker src/test/java/de/schmitzm/testing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jan 26 21:32:18 CET 2011


Author: alfonx
Date: 2011-01-26 21:32:17 +0100 (Wed, 26 Jan 2011)
New Revision: 1409

Added:
   trunk/schmitzm-core/src/main/java/de/schmitzm/net/
   trunk/schmitzm-core/src/main/java/de/schmitzm/net/Sitemap.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/io/IOUtilTest.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/net/
   trunk/schmitzm-core/src/test/java/de/schmitzm/net/SitemapTest.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/swing/swingworker/
   trunk/schmitzm-core/src/test/java/de/schmitzm/swing/swingworker/AtlasStatusDialogTest.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/testing/
   trunk/schmitzm-core/src/test/java/de/schmitzm/testing/SwingUtilTest.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingClass.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingUtil.java
Removed:
   trunk/schmitzm-core/src/main/java/de/schmitzm/Sitemap.java
Modified:
   trunk/schmitzm-core/pom.xml
Log:
some first tests....

Modified: trunk/schmitzm-core/pom.xml
===================================================================
--- trunk/schmitzm-core/pom.xml	2011-01-26 19:50:55 UTC (rev 1408)
+++ trunk/schmitzm-core/pom.xml	2011-01-26 20:32:17 UTC (rev 1409)
@@ -97,6 +97,7 @@
 			<scope>compile</scope>
 		</dependency>
 
+<!--
 		<dependency>
 			<groupId>net.sourceforge.jexcelapi</groupId>
 			<artifactId>jxl</artifactId>
@@ -111,7 +112,7 @@
 			<type>jar</type>
 			<scope>test</scope>
 		</dependency>
-
+-->
 		<dependency>
 			<groupId>commons-lang</groupId>
 			<artifactId>commons-lang</artifactId>

Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/Sitemap.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/Sitemap.java	2011-01-26 19:50:55 UTC (rev 1408)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/Sitemap.java	2011-01-26 20:32:17 UTC (rev 1409)
@@ -1,219 +0,0 @@
-package de.schmitzm;
-
-import java.io.FileWriter;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLEncoder;
-import java.util.Date;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.apache.log4j.Logger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/**
- * This class provides an easy way to list all pages of your site (including
- * generates ones) ina sitemap.xml. See http://sitemaps.org/protocol.php for the
- * XML specification.
- * 
- * <br/>
- * XML output is based on org.w3c.dom
- * 
- * 
- * @author Stefan Tzeggai
- */
-public class Sitemap {
-
-	static String[] SEARCHENGINES = new String[] {
-			"http://www.sitemapwriter.com/notify.php?crawler=all&url=",
-			"http://submissions.ask.com/ping?sitemap=",
-			"http://www.google.com/webmasters/tools/ping?sitemap=",
-			"http://api.moreover.com/ping?u=",
-			"http://www.bing.com/webmaster/ping.aspx?siteMap=",
-			"http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=" };
-
-	final static Logger log = Logger.getLogger(Sitemap.class);
-
-	private Document document;
-
-	final private Element urlsetElement;
-
-	/**
-	 * Returns the number of URLs. May not be more than 50,000 by spec.
-	 */
-	private int size = 0;
-
-	final static String NSURL = "http://www.sitemaps.org/schemas/sitemap/0.9";
-
-	public enum CHANGEFREQ {
-		monthly, daily, weekly
-	}
-
-	public Sitemap() {
-
-		try {
-
-			// Create a DOM builder and parse the fragment
-			final DocumentBuilderFactory factory = DocumentBuilderFactory
-					.newInstance();
-			document = factory.newDocumentBuilder().newDocument();
-
-			// XML root element
-			urlsetElement = document.createElementNS(NSURL, "urlset");
-			document.appendChild(urlsetElement);
-
-			// // Linking this XML to the AtlasML Schema
-			// final Attr namespaces = document.createAttributeNS(
-			// "http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
-			// namespaces
-			// .setValue(NSURL+" http://localhost:"
-			// + Webserver.DEFAULTPORT
-			// + "/skrueger/atlas/resource/AtlasML.xsd");
-			// urlset.setAttributeNode(namespaces);
-
-		} catch (Exception e) {
-			throw new RuntimeException(
-					"Sitemap org.w3c.xml newDocumentBuilder failed:", e);
-		}
-	}
-
-	/**
-	 * 
-	 * @param locString
-	 * @param lastmod
-	 *            when was the page modified the last time? May be
-	 *            <code>null</code>.
-	 * @param changefreq
-	 *            How often does the page change. May be <code>null</code>.
-	 * @param priority
-	 *            Priority 0.0 - 1.0. May be <code>null</code>.
-	 * @return <code>true</code> if the {@link Sitemap} contains less than 50000
-	 *         urls and the page was added.
-	 */
-	public boolean addUrl(String locString, Date lastmod,
-			CHANGEFREQ changefreq, Double priority) {
-		size++;
-		if (size >= 50000)
-			return false;
-
-		Element urlElement = document.createElement("url");
-
-		if (locString == null)
-			throw new IllegalArgumentException("location must be provided");
-		else {
-			Element e = document.createElement("loc");
-			e.appendChild(document.createTextNode(locString));
-			urlElement.appendChild(e);
-		}
-
-		if (lastmod != null) {
-			Element e = document.createElement("lastmod");
-			e.appendChild(document.createTextNode(lastmod.toString()));
-			urlElement.appendChild(e);
-		}
-
-		if (changefreq != null) {
-			Element e = document.createElement("changefreq");
-			e.appendChild(document.createTextNode(changefreq.toString()));
-			urlElement.appendChild(e);
-		}
-
-		if (priority != null) {
-			Element e = document.createElement("priority");
-			e.appendChild(document.createTextNode(priority.toString()));
-			urlElement.appendChild(e);
-		}
-		urlsetElement.appendChild(urlElement);
-		return true;
-	}
-
-	public Document getDocument() {
-		return document;
-	}
-
-	public String getXmlString() {
-		StringWriter stringWriter = new StringWriter();
-		outputToWriter(stringWriter);
-		return stringWriter.toString();
-	}
-
-	/**
-	 * Can be used to write to a File with {@link FileWriter}.
-	 */
-	public void outputToWriter(Writer stringWriter) {
-		try {
-
-			try { // close outputStreamWriter.close();
-
-				// ****************************************************************************
-				// Create the XML
-				// ****************************************************************************
-				final Result result = new StreamResult(stringWriter);
-
-				// with indenting to make it human-readable
-				final TransformerFactory tf = TransformerFactory.newInstance();
-
-				// TODO Ging mit xerces, geht nicht mehr mit xalan ?!
-				// tf.setAttribute("indent-number", new Integer(2));
-
-				final Transformer xformer = tf.newTransformer();
-				xformer.setOutputProperty(OutputKeys.INDENT, "yes");
-				xformer.setOutputProperty(
-						"{http://xml.apache.org/xalan}indent-amount", "2");
-
-				// Write the DOM document to the file
-				xformer.transform(new DOMSource(document), result);
-
-			} finally {
-				stringWriter.close();
-			}
-
-		} catch (Exception e) {
-			log.error("Failed to create sitemap.XML-String", e);
-			throw new RuntimeException(e);
-		}
-	}
-
-	public int getSize() {
-		return size;
-	}
-
-	public static void submitToSearchEngines(String urlToSitemap) {
-		try {
-
-			urlToSitemap = URLEncoder.encode(urlToSitemap, "UTF-8");
-			for (String se : SEARCHENGINES) {
-				log.info("Submitting " + urlToSitemap + " to " + se);
-				try {
-					URL url = new URL(se + urlToSitemap);
-
-					URLConnection openConnection = url.openConnection();
-					if (openConnection instanceof HttpURLConnection) {
-						HttpURLConnection httpconnection = ((HttpURLConnection) openConnection);
-						if (httpconnection.getResponseCode() != 200) {
-							log.error(se + " returned ResponseCode "
-									+ httpconnection.getResponseCode()
-									+ " for " + urlToSitemap);
-						}
-					}
-
-				} catch (Exception e) {
-					log.error("failed to submit " + urlToSitemap + " to " + se,
-							e);
-				}
-			}
-		} catch (Exception e) {
-			log.error("Error URL encoding " + urlToSitemap, e);
-		}
-	}
-}

Copied: trunk/schmitzm-core/src/main/java/de/schmitzm/net/Sitemap.java (from rev 1406, trunk/schmitzm-core/src/main/java/de/schmitzm/Sitemap.java)
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/Sitemap.java	2011-01-26 19:44:40 UTC (rev 1406)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/net/Sitemap.java	2011-01-26 20:32:17 UTC (rev 1409)
@@ -0,0 +1,219 @@
+package de.schmitzm.net;
+
+import java.io.FileWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.Date;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * This class provides an easy way to list all pages of your site (including
+ * generates ones) ina sitemap.xml. See http://sitemaps.org/protocol.php for the
+ * XML specification.
+ * 
+ * <br/>
+ * XML output is based on org.w3c.dom
+ * 
+ * 
+ * @author Stefan Tzeggai
+ */
+public class Sitemap {
+
+	static String[] SEARCHENGINES = new String[] {
+			"http://www.sitemapwriter.com/notify.php?crawler=all&url=",
+			"http://submissions.ask.com/ping?sitemap=",
+			"http://www.google.com/webmasters/tools/ping?sitemap=",
+			"http://api.moreover.com/ping?u=",
+			"http://www.bing.com/webmaster/ping.aspx?siteMap=",
+			"http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=" };
+
+	final static Logger log = Logger.getLogger(Sitemap.class);
+
+	private Document document;
+
+	final private Element urlsetElement;
+
+	/**
+	 * Returns the number of URLs. May not be more than 50,000 by spec.
+	 */
+	private int size = 0;
+
+	final static String NSURL = "http://www.sitemaps.org/schemas/sitemap/0.9";
+
+	public enum CHANGEFREQ {
+		monthly, daily, weekly
+	}
+
+	public Sitemap() {
+
+		try {
+
+			// Create a DOM builder and parse the fragment
+			final DocumentBuilderFactory factory = DocumentBuilderFactory
+					.newInstance();
+			document = factory.newDocumentBuilder().newDocument();
+
+			// XML root element
+			urlsetElement = document.createElementNS(NSURL, "urlset");
+			document.appendChild(urlsetElement);
+
+			// // Linking this XML to the AtlasML Schema
+			// final Attr namespaces = document.createAttributeNS(
+			// "http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
+			// namespaces
+			// .setValue(NSURL+" http://localhost:"
+			// + Webserver.DEFAULTPORT
+			// + "/skrueger/atlas/resource/AtlasML.xsd");
+			// urlset.setAttributeNode(namespaces);
+
+		} catch (Exception e) {
+			throw new RuntimeException(
+					"Sitemap org.w3c.xml newDocumentBuilder failed:", e);
+		}
+	}
+
+	/**
+	 * 
+	 * @param locString
+	 * @param lastmod
+	 *            when was the page modified the last time? May be
+	 *            <code>null</code>.
+	 * @param changefreq
+	 *            How often does the page change. May be <code>null</code>.
+	 * @param priority
+	 *            Priority 0.0 - 1.0. May be <code>null</code>.
+	 * @return <code>true</code> if the {@link Sitemap} contains less than 50000
+	 *         urls and the page was added.
+	 */
+	public boolean addUrl(String locString, Date lastmod,
+			CHANGEFREQ changefreq, Double priority) {
+		size++;
+		if (size >= 50000)
+			return false;
+
+		Element urlElement = document.createElement("url");
+
+		if (locString == null)
+			throw new IllegalArgumentException("location must be provided");
+		else {
+			Element e = document.createElement("loc");
+			e.appendChild(document.createTextNode(locString));
+			urlElement.appendChild(e);
+		}
+
+		if (lastmod != null) {
+			Element e = document.createElement("lastmod");
+			e.appendChild(document.createTextNode(lastmod.toString()));
+			urlElement.appendChild(e);
+		}
+
+		if (changefreq != null) {
+			Element e = document.createElement("changefreq");
+			e.appendChild(document.createTextNode(changefreq.toString()));
+			urlElement.appendChild(e);
+		}
+
+		if (priority != null) {
+			Element e = document.createElement("priority");
+			e.appendChild(document.createTextNode(priority.toString()));
+			urlElement.appendChild(e);
+		}
+		urlsetElement.appendChild(urlElement);
+		return true;
+	}
+
+	public Document getDocument() {
+		return document;
+	}
+
+	public String getXmlString() {
+		StringWriter stringWriter = new StringWriter();
+		outputToWriter(stringWriter);
+		return stringWriter.toString();
+	}
+
+	/**
+	 * Can be used to write to a File with {@link FileWriter}.
+	 */
+	public void outputToWriter(Writer stringWriter) {
+		try {
+
+			try { // close outputStreamWriter.close();
+
+				// ****************************************************************************
+				// Create the XML
+				// ****************************************************************************
+				final Result result = new StreamResult(stringWriter);
+
+				// with indenting to make it human-readable
+				final TransformerFactory tf = TransformerFactory.newInstance();
+
+				// TODO Ging mit xerces, geht nicht mehr mit xalan ?!
+				// tf.setAttribute("indent-number", new Integer(2));
+
+				final Transformer xformer = tf.newTransformer();
+				xformer.setOutputProperty(OutputKeys.INDENT, "yes");
+				xformer.setOutputProperty(
+						"{http://xml.apache.org/xalan}indent-amount", "2");
+
+				// Write the DOM document to the file
+				xformer.transform(new DOMSource(document), result);
+
+			} finally {
+				stringWriter.close();
+			}
+
+		} catch (Exception e) {
+			log.error("Failed to create sitemap.XML-String", e);
+			throw new RuntimeException(e);
+		}
+	}
+
+	public int getSize() {
+		return size;
+	}
+
+	public static void submitToSearchEngines(String urlToSitemap) {
+		try {
+
+			urlToSitemap = URLEncoder.encode(urlToSitemap, "UTF-8");
+			for (String se : SEARCHENGINES) {
+				log.info("Submitting " + urlToSitemap + " to " + se);
+				try {
+					URL url = new URL(se + urlToSitemap);
+
+					URLConnection openConnection = url.openConnection();
+					if (openConnection instanceof HttpURLConnection) {
+						HttpURLConnection httpconnection = ((HttpURLConnection) openConnection);
+						if (httpconnection.getResponseCode() != 200) {
+							log.error(se + " returned ResponseCode "
+									+ httpconnection.getResponseCode()
+									+ " for " + urlToSitemap);
+						}
+					}
+
+				} catch (Exception e) {
+					log.error("failed to submit " + urlToSitemap + " to " + se,
+							e);
+				}
+			}
+		} catch (Exception e) {
+			log.error("Error URL encoding " + urlToSitemap, e);
+		}
+	}
+}


Property changes on: trunk/schmitzm-core/src/main/java/de/schmitzm/net/Sitemap.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/io/IOUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/io/IOUtilTest.java	2011-01-26 19:50:55 UTC (rev 1408)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/io/IOUtilTest.java	2011-01-26 20:32:17 UTC (rev 1409)
@@ -0,0 +1,92 @@
+package de.schmitzm.io;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+public class IOUtilTest extends TestingClass {
+	@Test
+	public void testZipDir() throws IOException {
+		// Verzeichnisstruktr erstellen
+		File d0 = new File(IOUtil.getTempDir(), "testDir"
+				+ System.currentTimeMillis());
+		File d1 = new File(d0, "d1");
+		d1.mkdirs();
+
+		File f1 = new File(d1, "f1");
+		f1.createNewFile();
+		PrintWriter printWriter = new PrintWriter(f1);
+		printWriter.write("test");
+		printWriter.close();
+		assertTrue(f1.length() > 0l);
+
+		File zipFile = File.createTempFile("test", ".zip");
+		IOUtil.zipDir(d0, zipFile, d0);
+
+		System.out.println(d0);
+		System.out.println(f1);
+		System.out.println(zipFile);
+
+		assertTrue(zipFile.length() > 0l);
+
+	}
+
+	@Test
+	public void testCopyUrl() throws IOException, URISyntaxException {
+
+		File srcFile = File.createTempFile("junit", "");
+		URL source = IOUtil.fileToURL(srcFile);
+		assertNotNull(source);
+		File dest = File.createTempFile("junit", "");
+
+		dest.delete();
+		assertFalse("File must not exists before", dest.exists());
+
+		IOUtil.copyUrl(source, dest, false);
+
+		assertFalse(
+				"The destination file must not exist, because the original name was applied during copying",
+				dest.exists());
+	}
+
+	@Test
+	public void testGetFilename() throws MalformedURLException {
+		assertEquals("index.html", IOUtil.getFilename(new URL(
+				"http://www.bahn.de/exterme/index.html?k=v")));
+
+		assertEquals("index.html", IOUtil.getFilename(new URL(
+				"http://www.bahn.de/exterme/index.html")));
+
+		assertEquals("exterme",
+				IOUtil.getFilename(new URL("http://www.bahn.de/exterme/")));
+
+		assertEquals("exterme",
+				IOUtil.getFilename(new URL("http://www.bahn.de/exterme")));
+	}
+
+	@Test
+	public void testGetFileFromJarFileUrl() throws MalformedURLException
+	{
+		URL u = new URL("jar:file:/home/stefan/.m2/repository/org/geopublishing/geopublisher/gpcore/1.7-SNAPSHOT/gpcore-1.7-SNAPSHOT-tests.jar!/atlases/ChartDemoAtlas/atlas.gpa");
+		
+		assertEquals("/home/stefan/.m2/repository/org/geopublishing/geopublisher/gpcore/1.7-SNAPSHOT/gpcore-1.7-SNAPSHOT-tests.jar", IOUtil.getFileFromJarFileUrl(u).toString());
+	}
+
+	@Test
+	public void testCleanFilename()
+	{
+		assertEquals( "geopublisher_poster.pdf", IOUtil.cleanFilename("Geopublisher Poster.pdf"));
+		assertEquals( "geopublisher_poster.pdf", IOUtil.cleanFilename("Geopublisher%20Poster.pdf"));
+	}
+}


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/io/IOUtilTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/net/SitemapTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/net/SitemapTest.java	2011-01-26 19:50:55 UTC (rev 1408)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/net/SitemapTest.java	2011-01-26 20:32:17 UTC (rev 1409)
@@ -0,0 +1,19 @@
+package de.schmitzm.net;
+
+import org.junit.Test;
+
+import de.schmitzm.net.Sitemap.CHANGEFREQ;
+import de.schmitzm.testing.TestingClass;
+
+public class SitemapTest extends TestingClass {
+	
+	@Test
+	public void testGetDocument() {
+		Sitemap s = new Sitemap();
+		s.addUrl("http://www.wikisquare.de/UeberUns", null, CHANGEFREQ.monthly, 0.6);
+		s.addUrl("http://www.wikisquare.de/publications", null, null, null);
+		String xml = s.getXmlString();
+		System.out.println(xml);
+	}
+
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/net/SitemapTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/swing/swingworker/AtlasStatusDialogTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/swing/swingworker/AtlasStatusDialogTest.java	2011-01-26 19:50:55 UTC (rev 1408)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/swing/swingworker/AtlasStatusDialogTest.java	2011-01-26 20:32:17 UTC (rev 1409)
@@ -0,0 +1,52 @@
+package de.schmitzm.swing.swingworker;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Locale;
+
+import org.junit.Test;
+
+import de.schmitzm.swing.formatter.MbDecimalFormatter;
+import de.schmitzm.testing.TestingClass;
+public class AtlasStatusDialogTest extends TestingClass {
+
+	@Test
+	/**
+	2010-11-04 01:06:17,953 DEBUG internal.AtlasStatusDialog - progress http://atlas.geopublishing.org/atlases_testing/iida/raster_landsat00813704070.jar null 31469472 61469472 80
+	 */
+	public void formatProcessMessageJNLP() throws MalformedURLException {
+		URL url = new URL(
+				"http://atlas.geopublishing.org/atlases_testing/iida/raster_landsat00813704070.jar");
+
+		extracted(url);
+
+	}
+
+	private void extracted(URL url) {
+		int percentage = 40;
+		long full = 61469472;
+		Locale.setDefault(Locale.GERMAN);
+		String formated = new MbDecimalFormatter().format(full);
+
+		assertEquals("58,6Mb", formated);
+
+		String shorter = AtlasStatusDialog.getShortFilename(url);
+		assertEquals("raster_landsat", shorter);
+	}
+	
+	@Test
+	/**
+	2010-11-04 01:06:17,953 DEBUG internal.AtlasStatusDialog - progress http://atlas.geopublishing.org/atlases_testing/iida/raster_landsat00813704070.jar null 31469472 61469472 80
+	 */
+	public void formatProcessMessageJNLP2() throws MalformedURLException {
+		URL url = new URL(
+				"http://atlas.geopublishing.org/atlases_testing/iida/raster_landsat_00813704070.jar");
+
+		extracted(url);
+
+	}
+
+
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/swing/swingworker/AtlasStatusDialogTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/testing/SwingUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/testing/SwingUtilTest.java	2011-01-26 19:50:55 UTC (rev 1408)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/testing/SwingUtilTest.java	2011-01-26 20:32:17 UTC (rev 1409)
@@ -0,0 +1,63 @@
+package de.schmitzm.testing;
+
+import static org.junit.Assert.assertEquals;
+
+import java.awt.Color;
+
+import org.junit.Test;
+
+import de.schmitzm.swing.ExceptionDialog;
+import de.schmitzm.swing.FileInputOption;
+import de.schmitzm.swing.ManualInputOption;
+import de.schmitzm.swing.ManualInputOption.PasswordViewable;
+import de.schmitzm.swing.MultipleOptionPane;
+import de.schmitzm.swing.SelectionInputOption;
+import de.schmitzm.swing.SwingUtil;
+public class SwingUtilTest extends TestingClass {
+
+    @Test
+    public void textExceptionDialog() {
+      ExceptionDialog.setMailDestinationAddress("test at test.com");
+      if ( !TestingUtil.isInteractive() )
+        return;
+      ExceptionDialog.show( new Exception("Test exception") );
+    }
+  
+    @Test
+	public void testConvertColorToHexColor() {
+		assertEquals("#0000ff", SwingUtil.convertColorToHex(Color.BLUE));
+	}
+  
+  
+	@Test
+	public void testConvertColorToHexColorBooleanBoolean() {
+		assertEquals("#ff0000ff", SwingUtil.convertColorToHex(Color.RED, true,
+				true));
+		assertEquals("#00ff00", SwingUtil.convertColorToHex(Color.GREEN, false,
+				true));
+		assertEquals("0000ff", SwingUtil.convertColorToHex(Color.BLUE, false,
+				false));
+	}
+
+	@Test
+    public void testPasswortInputOption() {
+      if ( !TestingUtil.isInteractive() )
+        return;
+      
+      PasswordViewable pwInputOption = new ManualInputOption.PasswordViewable("Ein Passwort","Geheim");
+      pwInputOption.setPasswortVisible(false);
+      Object[] values = MultipleOptionPane.showMultipleInputDialog(
+            null, 
+            "Test Passwort",
+            pwInputOption,
+            new ManualInputOption.Text("blablabla"),
+            new FileInputOption("Eine Datei eingeben:",false),
+            new SelectionInputOption.Combo<String>("Eine Auswahl:",true,new String[] {"A","B","C"},null),
+            new SelectionInputOption.Radio<String>("Noch eine Auswahl:",true,new String[] {"A","B","C"},null)
+      );
+      if ( values == null )
+        System.out.println("Dialog aborted without passwort.");
+      else
+        System.out.println("Passwort was: "+ new String((char[])values[0]));
+    }
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/testing/SwingUtilTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingClass.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingClass.java	2011-01-26 19:50:55 UTC (rev 1408)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingClass.java	2011-01-26 20:32:17 UTC (rev 1409)
@@ -0,0 +1,32 @@
+package de.schmitzm.testing;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Abstract super class for our test classes to initialize some general stuff,
+ * e.g. logger.
+ * 
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public abstract class TestingClass {
+	// instantiate TestingUtil to initialize the Log4J appender
+	static {
+		new TestingUtil();
+	}
+
+	/** Logger for our testing classes. */
+	protected static Logger log = Logger.getLogger(TestingClass.class);
+
+	/**
+	 * @return Description of current memory status (e.g. "12/64MB free")
+	 */
+	protected final static String getMemoryInfo() {
+		Runtime rt = Runtime.getRuntime();
+		long max = rt.maxMemory();
+		long free = rt.freeMemory();
+		long total = rt.totalMemory();
+		return ((max - total + free) / 1024 / 1024) + "/" + (max / 1024 / 1024)
+				+ "Mb free";
+	}
+
+}


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingClass.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingUtil.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingUtil.java	2011-01-26 19:50:55 UTC (rev 1408)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingUtil.java	2011-01-26 20:32:17 UTC (rev 1409)
@@ -0,0 +1,250 @@
+package de.schmitzm.testing;
+
+import static org.junit.Assert.assertTrue;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dialog.ModalExclusionType;
+import java.awt.GraphicsEnvironment;
+import java.awt.Image;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.apache.log4j.Level;
+import org.junit.Ignore;
+
+import de.schmitzm.io.IOUtil;
+import de.schmitzm.lang.LangUtil;
+import de.schmitzm.swing.ExceptionDialog;
+
+
+/**
+ * Helpers to test Swing applications in general. <br/>
+ * If not set to @Ignore, HUDSON will complain
+ * "java.lang.Exception: No runnable methods"
+ */
+ at Ignore
+public class TestingUtil {
+
+	static {
+		LangUtil.initializeDefaultLogger(Level.DEBUG, null);
+	}
+
+	/**
+	 * All these GUI-initiating testGui(...) methods are only executed if the
+	 * system is not running in headless mode.
+	 */
+	public static final boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
+
+	/**
+	 * Number of seconds to wait until a GUI should be closed by default. Can be
+	 * set to -1 to always wait forever.
+	 */
+	private static final int WAIT_MAX_DEFAULT = 3;
+
+	private static boolean checkPixel(BufferedImage bi, int x, int y,
+			Color expected) {
+		final int rgb = bi.getRGB(x, y);
+
+		final Color found = new Color(rgb, true);
+
+		final boolean equals = expected.equals(found);
+
+		if (!equals) {
+			System.err.println("At pixel (" + x + "/" + y + ") expected "
+					+ expected + " but found " + found);
+		}
+
+		return equals;
+	}
+
+	/**
+	 * Checks whether an image has a specific color/transparency at a special
+	 * pixel position.
+	 */
+	public static boolean checkPixel(BufferedImage bi, int x, int y,
+			Float... colorParts) {
+
+		Color expectedColor = new Color(colorParts[0], colorParts[1],
+				colorParts[2], colorParts[3]);
+
+		return checkPixel(bi, x, y, expectedColor);
+
+	}
+
+	public static boolean checkPixel(BufferedImage bi, int x, int y,
+			int... colorParts) {
+
+		Color expectedColor;
+
+		if (colorParts.length == 4) {
+			expectedColor = new Color(colorParts[0], colorParts[1],
+					colorParts[2], colorParts[3]);
+		} else {
+			expectedColor = new Color(colorParts[0], colorParts[1],
+					colorParts[2]);
+		}
+
+		return checkPixel(bi, x, y, expectedColor);
+	}
+
+
+	/**
+	 * Returns the percentage of the possible maximum head size used (0 to 100)
+	 */
+	public static double getHeapUsedPercentageOfMax() {
+
+		// Get current size of heap in bytes
+		long heapSize = Runtime.getRuntime().totalMemory();
+
+		// Get maximum size of heap in bytes. The heap cannot grow beyond this
+		// size.
+		// Any attempt will result in an OutOfMemoryException.
+		long heapMaxSize = Runtime.getRuntime().maxMemory();
+
+		// Get amount of free memory within the heap in bytes. This size will
+		// increase
+		// after garbage collection and decrease as new objects are created.
+		long heapFreeSize = Runtime.getRuntime().freeMemory();
+
+		long used = (heapSize - heapFreeSize);
+
+		double perc = (used * 100. / heapMaxSize);
+
+		return perc;
+	}
+
+	public static boolean isInteractive() {
+		return INTERACTIVE;
+	}
+
+	public static void testGui(Component gui) throws Throwable {
+		testGui(gui, WAIT_MAX_DEFAULT);
+	}
+
+	public static void testGui(Component gui, int waitMax) throws Throwable {
+		testGui(gui, gui.getClass().getSimpleName(), waitMax);
+	}
+
+	/**
+	 * Opens a {@link JFrame} and shows the passed {@link JComponent}. If a
+	 * {@link ExceptionDialog} is opens in the GUI, an exception is thrown.<br/>
+	 * The test is skipped if the JVM is running headless.
+	 * 
+	 * @param gui
+	 * @param title
+	 *            can be used to explain the tests what to check
+	 * @param waitMax
+	 *            Maximum seconds to wait until the GUI should automatically
+	 *            close, set -1 for unlimieted
+	 */
+	public static void testGui(Component gui, String title, int waitMax)
+			throws Throwable {
+
+		if (GraphicsEnvironment.isHeadless())
+			return;
+
+		final AtomicBoolean stopFlag = new AtomicBoolean(false);
+
+		final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
+
+		ExceptionDialog.addListener(new ActionListener() {
+
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				err.set((Throwable) e.getSource());
+				stopFlag.set(true);
+			}
+		});
+
+		Window w = null;
+		if (gui instanceof Window) {
+			w = (Window) gui;
+		} else if (gui instanceof JComponent) {
+			JFrame f = new JFrame(title);
+			f.setContentPane((JComponent) gui);
+			f.pack();
+			w = f;
+		}
+
+		// If it is a modal dialog, unmodalize it
+		w.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
+
+		if (w instanceof JDialog) {
+			// JDialog.setModal must be unset additionally.
+			JDialog d = (JDialog) w;
+			d.setModal(false);
+		}
+
+		w.setVisible(true);
+		int countWait = 0;
+		while (w.isVisible() && !stopFlag.get()) {
+			LangUtil.sleepExceptionless(100);
+			if (waitMax >= 0 && countWait++ > waitMax * 10) {
+				// waitMax < 0 will never brake the waiting and never increase
+				// the countWait
+				break;
+			}
+		}
+		w.dispose();
+
+		if (stopFlag.get()) {
+			throw err.get();
+		}
+	}
+
+	public static void testGui(Image image, int waitMax) throws Throwable {
+
+		if (GraphicsEnvironment.isHeadless())
+			return;
+
+		JLabel imgLabel = new JLabel(new ImageIcon(image));
+		testGui(imgLabel, imgLabel.getClass().getSimpleName(), waitMax);
+	}
+//
+//	public static void testGui(JFreeChart chart, String frameTitle)
+//			throws Throwable {
+//		testGui(chart, frameTitle, WAIT_MAX_DEFAULT);
+//	}
+//
+//	public static void testGui(JFreeChart chart, String frameTitle, int waitMax)
+//			throws Throwable {
+//		if (isInteractive()) {
+//			ChartFrame chartFrame = new ChartFrame(frameTitle, chart);
+//			chartFrame.pack();
+//
+//			testGui(chartFrame, waitMax);
+//		}
+//	}
+
+	public static void testGui(JPanel jPanel, String title) throws Throwable {
+		testGui(jPanel, title, 3);
+	}
+
+	/**
+	 * @return Returns a freshly create new directory in the system's temp
+	 *         directory. TODO This would be a good place to register them to
+	 *         manage their deletion.
+	 * @throws IOException
+	 */
+	public static File getNewTempDir() throws IOException {
+		File file = new File(IOUtil.getTempDir(), File.createTempFile(
+				"deleteme", "").getName());
+		assertTrue(file.delete());
+		assertTrue(file.mkdir());
+		return file;
+	}
+}


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingUtil.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native



More information about the Schmitzm-commits mailing list