<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>web2.0goodies.com &#187; java</title>
	<atom:link href="http://web2.0goodies.com/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://web2.0goodies.com/blog</link>
	<description>Tips, Tricks, and How To's for Web 2.0</description>
	<lastBuildDate>Tue, 03 Jan 2012 05:34:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Generating Code from html tables using javascript.</title>
		<link>http://web2.0goodies.com/blog/java/generating-code-from-html-tables-using-javascript/</link>
		<comments>http://web2.0goodies.com/blog/java/generating-code-from-html-tables-using-javascript/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 20:59:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code generation]]></category>
		<category><![CDATA[code snippets]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://web2.0goodies.com/blog/?p=188</guid>
		<description><![CDATA[I frequently write sdks for different applications / sites. I frequently find when I do an integration of some kind for a customer the company does not provide a good sdk for the platform I am using. Because I prefer to make things easy. I usually like to write a tool to auto-generate an sdk [...]]]></description>
			<content:encoded><![CDATA[<p>I frequently write sdks for different applications / sites.  I frequently find when I do an integration of some kind for a customer the company does not provide a good sdk for the platform I am using.  Because I prefer to make things easy. I usually like to write a tool to auto-generate an sdk for that tool.</p>
<p>An example of this is my 3dcart sdk: <a href="http://code.google.com/p/3dcart-php-sdk/">http://code.google.com/p/3dcart-php-sdk/</a></p>
<p>While these sdks aren&#8217;t always perfect they allow me to create the integration MUCH faster. Which means I make more money.</p>
<p>Recently I needed to do this for Infusionsoft to create a simple integration that could access a few objects in java via their DataService api.  I didn&#8217;t need much, just 3 objects so that a fulfillment company could read order information from Infusionsoft.  When I worked at Infusionsoft I created a tool that took an xml file and automatically generated their api documentation.  Unfortunately, since I am no longer an employee I don&#8217;t have access to that xml document.  But!  I do have access to the public api documentation that my tool auto-generated.  And it&#8217;s in a table!</p>
<p>So, I quickly used the following code to auto generate the code for my class, my class factory (that populates the class from a map) and the code to populate a list of available fields.</p>
<p>It worked beautifully!  This same technique could be adapted to any well organized api documentation.  The page I used is located here: http://developers.infusionsoft.com/dbDocs/Contact.html</p>
<p>Remember if the page doesn&#8217;t have jQuery on it, just install it as follows:</p>
<pre name="code" class="javascript">
var s = document.createElement('script');
s.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js');
document.body.appendChild(s);
</pre>
<pre name="code" class="javascript">
jQuery('#staticFields, #publicFields, #factoryCode').remove();
jQuery('body').append('&lt;pre id="staticFields"&gt;&lt;/pre&gt; &lt;br/&gt;');
jQuery('body').append('&lt;pre id="publicFields"&gt;&lt;/pre&gt; &lt;br/&gt;');
jQuery('body').append('&lt;pre id="factoryCode"&gt;&lt;/pre&gt; &lt;br/&gt;');

jQuery('table tr').each(
    function(){
        var $this = jQuery(this);
        $tds = $this.find('td');
        if($tds.length == 3){
            jQuery('#staticFields').append('fields.add("' + jQuery($tds.get(0)).html() + '");\n');                   

            jQuery('#publicFields').append('public ' + jQuery($tds.get(1)).html() + ' ' + jQuery($tds.get(0)).html().substr(0, 1).toLowerCase() + jQuery($tds.get(0)).html().substr(1) + ';\n');                   

            jQuery('#factoryCode').append('contact.' + jQuery($tds.get(0)).html().substr(0, 1).toLowerCase() + jQuery($tds.get(0)).html().substr(1) + ' = (' + jQuery($tds.get(1)).html() + ') map.get("' + jQuery($tds.get(0)).html()+ '");\n');                   

        }
    }
);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://web2.0goodies.com/blog/java/generating-code-from-html-tables-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why you NEED to become framiliar with Maven.</title>
		<link>http://web2.0goodies.com/blog/java/why-you-need-to-become-framiliar-with-maven/</link>
		<comments>http://web2.0goodies.com/blog/java/why-you-need-to-become-framiliar-with-maven/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 21:23:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://web2.0goodies.com/blog/java/why-you-need-to-become-framiliar-with-maven/</guid>
		<description><![CDATA[If you program in Java, you NEED to become fluent in Maven. Why?&#160; Because it simplifies working on projects a lot.&#160; Specifics: Lots of utilities that can be run on any and all maven projects at any time with only one command, and without downloading anything manual. Generate Javadocs instantly.(mvn javadoc:javadoc) Run all tests with [...]]]></description>
			<content:encoded><![CDATA[<p>If you program in Java, you NEED to become fluent in Maven.</p>
<p>Why?&nbsp; Because it simplifies working on projects a lot.&nbsp; </p>
<p>Specifics:
<ul>
<li>Lots of utilities that can be run on any and all maven projects at any time with only one command, and without downloading anything manual.</li>
<li>Generate Javadocs instantly.(mvn javadoc:javadoc)</li>
<li>Run all tests with one command and receive pretty html reports of your test results.(mvn test)</li>
<li>View Test Code coverage with one command and no downloading. (mvn cobertura:cobertra)</li>
<li>Almost instantly use the latest Java libraries, like Apache Commons. (IDE detects unknown class and prompts you to add a dependency to your project).</li>
<li>Do selenium testing with one command. (mvn selenium:start-server)</li>
<li>Generate web projects that include Hibernate, Spring, and more in minutes. (mvn archetype generate)</li>
<li>Run your tomcat projects with a single command. (mvn tomcat:run)</li>
<li>And more!!!&nbsp; If you develop in Java,&nbsp; learning Maven will increase productivity a lot.</li>
</ul>
<p>So, LEARN IT</p>
<p>Start off with this video: <span class="youtube">
<object width="425" height="355">
<param name="movie" value="http://www.youtube.com/v/rdhqAzHZkwc?color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0&amp;rel=1" />
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always">
<embed src="http://www.youtube.com/v/rdhqAzHZkwc?color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0&amp;rel=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="425" height="355"></embed>
</object>
</span><p><a href="http://www.youtube.com/watch?v=rdhqAzHZkwc">www.youtube.com/watch?v=rdhqAzHZkwc</a></p></p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" alt="" src="http://img.zemanta.com/pixy.gif?x-id=0c0efc65-12b5-8af1-836c-fe21da3e2210" /></div>
]]></content:encoded>
			<wfw:commentRss>http://web2.0goodies.com/blog/java/why-you-need-to-become-framiliar-with-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring MVC Redirect using &#8220;redirect:url&#8221; syntax.</title>
		<link>http://web2.0goodies.com/blog/java/spring-mvc-redirect-using-redirecturl-syntax/</link>
		<comments>http://web2.0goodies.com/blog/java/spring-mvc-redirect-using-redirecturl-syntax/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 17:45:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[http]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://web2.0goodies.com/blog/java/spring-mvc-redirect-using-redirecturl-syntax/</guid>
		<description><![CDATA[I searched online for how to do redirects from a controller, and only came up with the RedirectView&#8230; But I KNEW there was an easier way I had seen before&#8230; The key is make your controller function return a string&#8230;&#160; And then return &#8220;redirect:URL&#8221; instead of a view name.&#160; Violaa! Absolute and relative urls work [...]]]></description>
			<content:encoded><![CDATA[<p>I searched online for how to do redirects from a controller, and only came up with the RedirectView&#8230;</p>
<p>But I KNEW there was an easier way I had seen before&#8230;</p>
<p>The key is make your controller function return a string&#8230;&nbsp; And then return &#8220;redirect:URL&#8221; instead of a view name.&nbsp; Violaa!</p>
<p>Absolute and relative urls work great.</p>
<p>See: <a target="_blank" href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/view/UrlBasedViewResolver.html">Spring 3.0.x docs for UrlBasedViewResolver</a></p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" alt="" src="http://img.zemanta.com/pixy.gif?x-id=a83687bd-4abf-8d9d-a4b7-6ba860d94f33" /></div>
]]></content:encoded>
			<wfw:commentRss>http://web2.0goodies.com/blog/java/spring-mvc-redirect-using-redirecturl-syntax/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Oracle has wasted no time in Rebranding Sun products.</title>
		<link>http://web2.0goodies.com/blog/java/oracle-has-wasted-no-time-in-rebranding-sun-products/</link>
		<comments>http://web2.0goodies.com/blog/java/oracle-has-wasted-no-time-in-rebranding-sun-products/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 18:11:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[community]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sun]]></category>

		<guid isPermaLink="false">http://web2.0goodies.com/blog/java/oracle-has-wasted-no-time-in-rebranding-sun-products/</guid>
		<description><![CDATA[Unless you&#8217;ve been out of touch for a long time, you&#8217;ve heard that Sun bought MySql, and was subsequently bought by Oracle.&#160; If you use java, you&#8217;ve noticed that Oracle hasn&#8217;t drug their feet in rebranding sun products as Oracle&#8230;&#160; java url&#8217;s are now download.oracle.com instead of download.sun.com. MySQL appears to have escaped the re-branding [...]]]></description>
			<content:encoded><![CDATA[<p>Unless you&#8217;ve been out of touch for a long time, you&#8217;ve heard that Sun bought MySql, and was subsequently bought by Oracle.&nbsp; If you use java, you&#8217;ve noticed that Oracle hasn&#8217;t drug their feet in rebranding sun products as Oracle&#8230;&nbsp; java url&#8217;s are now download.oracle.com instead of download.sun.com. </p>
<p>MySQL appears to have escaped the re-branding at the moment.&nbsp; It will be interesting to see what Oracle does with it in the future&#8230;&nbsp; If they killed it, they would tick off half the development community in the world, making them less-likely to choose Oracle products in the future (let&#8217;s face it, there are LOTS of un-objective decision makers in the world).&nbsp; But they could put some spin on it, and use it to build their market share&#8230;&nbsp; Let&#8217;s wait and see&#8230;</p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" alt="" src="http://img.zemanta.com/pixy.gif?x-id=6e7d5499-bae6-8602-b6ec-a61f05fe6fef" /></div>
]]></content:encoded>
			<wfw:commentRss>http://web2.0goodies.com/blog/java/oracle-has-wasted-no-time-in-rebranding-sun-products/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MultiThreaded TestNG, Surefire Craziness.</title>
		<link>http://web2.0goodies.com/blog/java/multithreaded-testng-surefire-craziness/</link>
		<comments>http://web2.0goodies.com/blog/java/multithreaded-testng-surefire-craziness/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 18:53:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[testng]]></category>

		<guid isPermaLink="false">http://web2.0goodies.com/blog/?p=25</guid>
		<description><![CDATA[The Setup Maven 2.0.9 Surefire 2.4.3 TestNG version 5.8 The Craziness If you annotate a method to have an invocationCount of 2, and a threadPoolSize of 2, and your test fails in an @BeforeMethod or an @AfterMethod when run by surefire, the test run count reported by surefire will be inaccurate. Significantly innacurate at times. [...]]]></description>
			<content:encoded><![CDATA[<h1>The Setup</h1>
<p>Maven 2.0.9<br />
Surefire 2.4.3<br />
TestNG version 5.8</p>
<h1>The Craziness</h1>
<p>If you annotate a method to have an invocationCount of 2, and a threadPoolSize of 2, and your test fails in an @BeforeMethod or an @AfterMethod when run by surefire, the test run count reported by surefire will be inaccurate.  Significantly innacurate at times. </p>
<p>For example:</p>
<p><code><br />
package com.infusion.crm.application;</p>
<p>import org.testng.annotations.AfterMethod;<br />
import org.testng.annotations.BeforeMethod;<br />
import org.testng.AssertJUnit;<br />
import org.testng.annotations.Test;</p>
<p>/**<br />
 * Created by IntelliJ IDEA.<br />
 * User: joey<br />
 * Date: Jun 29, 2009<br />
 * Time: 3:19:13 PM<br />
 * To change this template use File | Settings | File Templates.<br />
 */<br />
public class TestThreadPoolSize {<br />
    @BeforeMethod<br />
    public void before(){<br />
        AssertJUnit.assertFalse(true);<br />
    }</p>
<p>    @Test<br />
    public void test1(){<br />
        AssertJUnit.assertFalse(true);<br />
    }<br />
}</p>
<p></code></p>
<p>Returns the following from maven test:</p>
<p><code><br />
-------------------------------------------------------<br />
 T E S T S<br />
-------------------------------------------------------<br />
Running TestSuite<br />
Tests run: 8, Failures: 1, Errors: 0, Skipped: 7, Time elapsed: 10.298 sec <<< FAILURE!</p>
<p>Results :</p>
<p>Failed tests:<br />
  before(com.infusion.crm.application.TestThreadPoolSize)</p>
<p>Tests run: 8, Failures: 1, Errors: 0, Skipped: 7</p>
<p></code></p>
<p>This problem is also manifested if you create an AnnotationTransformer that forces the invocationCount and threadPoolSize of a test to both be greater then 1.</p>
<p>This bug is only manifested when multiple threads are used.  If you set the invocation count to 20 and the thread pool size to 1, the bug does not appear.</p>
<p>Sometimes it is unpredictable and worse then just 2x the right number of tests. I ran a test, with 9 methods, and 4 threads, and a very exhaustive @BeforeMethod that takes several seconds to run.  It failed repeatedly and said: 142 test run, 3 failed, 139 skipped.</p>
]]></content:encoded>
			<wfw:commentRss>http://web2.0goodies.com/blog/java/multithreaded-testng-surefire-craziness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting jUnit test to TestNG tests.</title>
		<link>http://web2.0goodies.com/blog/java/converting-junit-test-to-testng-tests/</link>
		<comments>http://web2.0goodies.com/blog/java/converting-junit-test-to-testng-tests/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 18:20:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[maven sed]]></category>
		<category><![CDATA[testng]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://web2.0goodies.com/blog/?p=23</guid>
		<description><![CDATA[Update After writing the below script, and submitting my change for a code review, the reviewer pointed me to a TestNG provided tool that will convert them. So here it is: java org.testng.JUnitConverter -overwrite -annotation -srcdir src Be sure to include the testng jar, along with the $JAVA_HOME/lib/tools.jar in your classpath when you run that. [...]]]></description>
			<content:encoded><![CDATA[<h1>Update</h1>
<p>After writing the below script, and submitting my change for a code review, the reviewer pointed me to a TestNG provided tool that will convert them.  So here it is:</p>
<p><code>java org.testng.JUnitConverter -overwrite -annotation -srcdir src </code></p>
<p>Be sure to include the testng jar, along with the $JAVA_HOME/lib/tools.jar in your classpath when you run that.</p>
<h1>Original SED way of converting</h1>
<p>Because of the exceptional design of TestNG, this is a pretty simple text replace exercise.  Here is a shell script using sed that will do most of the work for you.  After it runs, just remove jUnit from your dependency list / classpath and re-compile, hand edit any errors.</p>
<p>There are two steps to running this, first, create a list of all the java files that contain junit references in your src.</p>
<p><code>find . -name "*.java" | xargs grep -L junit > toconvert</code></p>
<p>Then, use xargs to run the script on all the files. </p>
<p><code>cat toconvert | xargs testngify</code></p>
<p>Here is the contents of the testngify shell script:</p>
<p><code><br />
#!/bin/bash</p>
<p>IN_FILE=$1<br />
function replace {<br />
  OUT_FILE="${IN_FILE}'.tmp'"<br />
  #echo executing pattern: $1<br />
  sed "$1" < $IN_FILE > $OUT_FILE<br />
  rm $IN_FILE<br />
  mv $OUT_FILE $IN_FILE<br />
}</p>
<p>replace "s/import org\.junit\.After;/import org\.testng\.annotations\.AfterMethod;/g"<br />
replace "s/import org\.junit\.Assert;/import org\.testng\.AssertJUnit;/g"<br />
replace "s/import org\.junit\.Before;/import org\.testng\.annotations\.BeforeMethod;/g"<br />
replace "s/import org\.junit\.Test;/import org\.testng\.annotations\.Test;/g"<br />
replace "s/import junit\.framework\.Assert;/import org\.testng\.AssertJUnit;/g"<br />
replace "s/import\s*static\s*org\.junit\.Assert\.\*;/import static org\.testng\.AssertJUnit\.\*;/g"<br />
replace "s/import\s*static\s*org\.junit\.Assert\.assertEquals;/import static org\.testng\.AssertJUnit\.assertEquals;/g"<br />
replace "s/\(\s\)Assert\./\1AssertJUnit\./g"<br />
replace "s/import org\.junit\.Test;/import org\.testng\.annotations\.Test;/g"<br />
replace "s/\(@Test\s*\)(expected\s*=/\1(expectedExceptions =/g"<br />
replace "s/\(@Test\.*\)ComparisonFailure\.class/\1AssertionError\.class/g"<br />
replace "s/@After\s*$/@AfterMethod/g"<br />
replace "s/@Before\s*$/@BeforeMethod/g"<br />
replace "s/@Before()\s*$/@BeforeMethod/g"<br />
replace "s/org\.junit\.Assert\./org.testng.AssertJUnit\./g"<br />
replace "s/.*@Ignore(\"\(.*\)\")/\t@Test(enabled=false) \/\/\1/g"<br />
replace "s/\(.*\)@Ignore\(.*\)/\1\2/g"<br />
replace "s/^.*org\.junit.*$//g"<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://web2.0goodies.com/blog/java/converting-junit-test-to-testng-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

