<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Tag ejb</title>
    <link>http://blog.objectmentor.com/articles/tag/ejb</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>&amp;lt;a href=&amp;quot;http://infinitest.org/web/guest/home&amp;quot;&amp;gt;Infinitest&amp;lt;/A&amp;gt; for Java, have you tried it?</title>
      <description>&lt;h2&gt;Background&lt;/h2&gt;
About 2 years ago, I was working with &lt;a href="http://twitter.com/benrady"&gt;Ben Rady&lt;/a&gt; and he demonstrated something he was working on at the time: &lt;a href="http://infinitest.org/web/guest/home"&gt;Infinitest&lt;/A&gt;. As often I am, I was a little interested but mostly skeptical &amp;#8211; don&amp;#8217;t know if that came across or not.

	&lt;p&gt;Since then he and others (e.g., &lt;a href="http://twitter.com/rcoffin"&gt;Rod Coffin&lt;/a&gt; have made amazing strides and created plugins for both Eclipse and IntelliJ.&lt;/p&gt;


&lt;h2&gt;Taking it for a test run&lt;/h2&gt;
Earlier this month, I finally decided to give it a test drive. When I made that announcement, &lt;a href="http://twitter.com/benrady"&gt;Ben&lt;/a&gt; made the following (bold?) statement:
&lt;blockquote&gt;
For me, using Infinitest is as different from &lt;span class="caps"&gt;TDD&lt;/span&gt; as &lt;span class="caps"&gt;TDD&lt;/span&gt; is from not testing
&lt;/blockquote&gt;

	&lt;p&gt;So is that true? Is using a continuous test execution tool as different from not using one as using &lt;span class="caps"&gt;TDD&lt;/span&gt; is from not testing? I&amp;#8217;m not sure I&amp;#8217;m there yet. However, I will say my brain is having some difficulty getting used to the cool feedback.&lt;/p&gt;


	&lt;p&gt;Here are two recent experiences I had using it.&lt;/p&gt;


&lt;h2&gt;Classpath Issues&lt;/h2&gt;
Back at the end of 2006 I wrote a &lt;a href="http://schuchert.wikispaces.com/EJB+3+and+Java+Persistence+API"&gt;class on using &lt;span class="caps"&gt;JPA&lt;/span&gt; and &lt;span class="caps"&gt;EJB 3&lt;/span&gt;&lt;/a&gt;. I&amp;#8217;ve not really done much to update that material in some years but recently I had an email from someone trying to work through the first tutorial with little success. Over the past few years there&amp;#8217;s been some bit-rot. The embeddable container is not really up to date, &lt;span class="caps"&gt;EJB 3&lt;/span&gt;.1 includes an embeddable container as part of its spec, Hibernate has been updated, etc. 

So I spent a few hours tracking down updated jar files and building my classpath. I had already installed &lt;a href="http://infinitest.org/web/guest/home"&gt;Infinitest&lt;/A&gt; and I noticed as added I something to my classpath, &lt;a href="http://infinitest.org/web/guest/home"&gt;Infinitest&lt;/A&gt; would kick off and show a stack trace (my code was doing that in a @Before method). So I sped up what I was doing:
	&lt;ul&gt;
	&lt;li&gt;I directly edited the .classpath file in Eclipse&lt;/li&gt;
		&lt;li&gt;Saved what I was doing&lt;/li&gt;
		&lt;li&gt;Waited about a second&lt;/li&gt;
		&lt;li&gt;Noticed the new stack trace&lt;/li&gt;
		&lt;li&gt;Found the next jar file I needed to add&lt;/li&gt;
		&lt;li&gt;Repeat until tests passed.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Might sound like a bit of overkill, but in the end I built a classpath from scratch and I ended up adding 13 jar files. So it saved some time.&lt;/p&gt;


	&lt;p&gt;Note, I wasn&amp;#8217;t looking for this. I had only installed &lt;a href="http://infinitest.org/web/guest/home"&gt;Infinitest&lt;/A&gt; the day before so this was unexpected and welcome! Oh, and before my @Before method was handling the exception properly, &lt;a href="http://infinitest.org/web/guest/home"&gt;Infinitest&lt;/A&gt; showed that the code had a problem (it was in the @After with a null pointer exception), which it indicated as an error like a syntax error or a validation error. Nice!&lt;/p&gt;


&lt;h2&gt;Using &lt;a href="http://mockito.org/"&gt;Mockito&lt;/a&gt;&lt;/h2&gt;
I&amp;#8217;ve recently been using &lt;a href="http://mockito.org/"&gt;Mockito&lt;/a&gt;. You can review &lt;a href="http://blog.objectmentor.com/articles/2009/05/27/mockito-example-java-mocking-framework"&gt;a previous blog entry&lt;/a&gt; for that example. Today we&amp;#8217;re holding the first &lt;a href="http://codingdojo.org/"&gt;coding dojo&lt;/a&gt; at the recently opened &lt;a href="http://okccoco.com/"&gt;OkC CoCo&lt;/a&gt;. Last night I started working on the next problem I want to use for the next dojo. It involves practicing using a &lt;a href="http://www.martinfowler.com/articles/mocksArentStubs.html#ClassicalAndMockistTesting"&gt;mockist approach&lt;/a&gt;. I set up my classpath, started writing tests and immediately I noticed what looked like a syntax error on the verification step of my first unit test. I was confused thinking I had an actual syntax error since I&amp;#8217;m not quite to the point of touch-typing &lt;a href="http://mockito.org/"&gt;Mockito&lt;/a&gt; based tests (I did update Eclipse so I could &lt;a href="http://jdcarlflip.blogspot.com/2008/07/eclipse-tip-static-imports.html"&gt;more easily find the static imports&lt;/a&gt;).&lt;p/&gt;

	&lt;p&gt;Next, I updated my test to use the @Mock annotation. I removed the hand-written initialization and immediately I noticed a &amp;#8220;syntax&amp;#8221; error &amp;#8211; null pointer exception. I was immediately (OK 1 second later) showed the impact of removing a single line of code. I added the missing line to auto-initialize the @Mock annotated fields but I did it incorrectly, so the error remained. I finally got the line correct and the &amp;#8220;syntax error&amp;#8221; went away.&lt;/p&gt;


&lt;h2&gt;Observations&lt;/h2&gt;
Wow. That&amp;#8217;s what I have to say so far. I&amp;#8217;m not entirely sure the before and after of using &lt;a href="http://infinitest.org/web/guest/home"&gt;Infinitest&lt;/A&gt; is the same size as moving from not testing to using &lt;span class="caps"&gt;TDD&lt;/span&gt;. Maybe it&amp;#8217;s the same as moving from being &lt;a href="http://c2.com/cgi/wiki?TestInfected"&gt;Test Infected&lt;/a&gt; to practicing &lt;span class="caps"&gt;TDD&lt;/span&gt;. I was &lt;a href="http://c2.com/cgi/wiki?TestInfected"&gt;Test Infected&lt;/a&gt; several years before I practiced &lt;span class="caps"&gt;TDD&lt;/span&gt;. 

	&lt;p&gt;I was also about as skeptical that moving to &lt;span class="caps"&gt;TDD&lt;/span&gt; from being &lt;a href="http://c2.com/cgi/wiki?TestInfected"&gt;Test Infected&lt;/a&gt; was useful. I was wrong. History tends to repeat itself, so I&amp;#8217;m guessing, based on my initial resistance, that this is the future.&lt;/p&gt;


	&lt;p&gt;Embrace it.&lt;/p&gt;</description>
      <pubDate>Thu, 18 Jun 2009 11:35:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:e0b1e630-9d3c-4830-a1c9-87cfb0cea6d3</guid>
      <author>Brett Schuchert</author>
      <link>http://blog.objectmentor.com/articles/2009/06/18/infinitest-for-java-have-you-tried-it</link>
      <category>Schuchert's Scattered Synapses </category>
      <category>infinitest</category>
      <category>TDD</category>
      <category>test</category>
      <category>infected</category>
      <category>mock</category>
      <category>mockito</category>
      <category>ejb</category>
      <category>3</category>
      <category>jpa</category>
    </item>
    <item>
      <title>!define TEST_SYSTEM {fit:A} part II</title>
      <description>&lt;p&gt;In 11/2008 I wrote the &lt;a href="http://blog.objectmentor.com/articles/2008/11/03/define-test_system-fit-a"&gt;first part of this article&lt;/a&gt; but I really did not give the background on why I originally asked Bob to add this feature.&lt;/p&gt;


	&lt;p&gt;So why does FitNesse need to be able to run different parts of suites in different VM&amp;#8217;s?&lt;/p&gt;


	&lt;p&gt;Imagine you are testing services registered on an &lt;span class="caps"&gt;ESB&lt;/span&gt;. That &lt;span class="caps"&gt;ESB&lt;/span&gt; allows 
deployment of services as &lt;span class="caps"&gt;EJB&lt;/span&gt;&amp;#8217;s. There&amp;#8217;s something important about that fact.
By default, different &lt;span class="caps"&gt;EJB&lt;/span&gt;&amp;#8217;s run with their own class loader. You can dig into
the &lt;span class="caps"&gt;EJB&lt;/span&gt; spec if you&amp;#8217;d like, but there&amp;#8217;s roughly a hierarchy of 5 class loaders 
by the time you get to an executing &lt;span class="caps"&gt;EJB&lt;/span&gt; (can be more, could be less).&lt;/p&gt;


	&lt;p&gt;Why is this important? If two &lt;span class="caps"&gt;EJB&lt;/span&gt;&amp;#8217;s make reference to the &amp;#8220;same&amp;#8221; &lt;span class="caps"&gt;JAR&lt;/span&gt; file, 
then each could get loaded by the same or a different class loader. If the
&lt;span class="caps"&gt;JAR&lt;/span&gt; file is installed high in the class-loader hierarchy, then they will
be loaded by the same class loader instance and therefore will be the same
classes.&lt;/p&gt;


	&lt;p&gt;However, let&amp;#8217;s assume that each &lt;span class="caps"&gt;EJB&lt;/span&gt; represents ones service. Furthermore,
each &lt;span class="caps"&gt;EJB&lt;/span&gt; makes a reference to some &lt;span class="caps"&gt;JAR&lt;/span&gt; file directly, that is, it is not
visible to a hierarchically higher class loader. Then that same &lt;span class="caps"&gt;JAR&lt;/span&gt; file will
get loaded twice, once by each class loader (this really happens), and those
exact same classes will be considered different.&lt;/p&gt;


	&lt;p&gt;That&amp;#8217;s right, the exact same &lt;span class="caps"&gt;JAR&lt;/span&gt; file loaded by 2 different class loaders are 
treated as unrelated classes.&lt;/p&gt;


	&lt;p&gt;In reality, each deployed &lt;span class="caps"&gt;EJB&lt;/span&gt; is &amp;#8220;complete&amp;#8221; in that in includes the &lt;span class="caps"&gt;JAR&lt;/span&gt;&amp;#8217;s it
needs to execute. So the &amp;#8220;same&amp;#8221; jar &amp;#8211; same in terms of file contents &amp;#8211; exists
twice in the system and is loaded by two class loaders.&lt;/p&gt;


	&lt;p&gt;Now, it gets a little worse. Those two &lt;span class="caps"&gt;EJB&lt;/span&gt;&amp;#8217;s work off a &amp;#8220;common&amp;#8221; data model.
Common in that the underlying business objects are common across a set of
applications. However, the common data model is a moving target (it&amp;#8217;s grown
as needed). To manage complexity, not all services are forced to update to the
latest version of the common data model at the same time (it&amp;#8217;s not really a
manageable solution &amp;#8211; generally).&lt;/p&gt;


	&lt;p&gt;So now we have 2 (really several) &lt;span class="caps"&gt;EJB&lt;/span&gt;&amp;#8217;s that refer to logically the same &lt;span class="caps"&gt;JAR&lt;/span&gt;
but different versions. Luckily, this is&lt;i&gt; &lt;b&gt;no&lt;/i&gt;&lt;/b&gt; problem because 
each &lt;span class="caps"&gt;EJB&lt;/span&gt; has its own class loader, so it is OK for 2 &lt;span class="caps"&gt;EJB&lt;/span&gt;&amp;#8217;s to refer to 
different versions of the same logical data model.&lt;/p&gt;


	&lt;p&gt;How does any of this have&lt;i&gt; &lt;b&gt;anything&lt;/i&gt;&lt;/b&gt; to do with FitNesse? When
FitNesse executes a suite, by default all tests are executed in the same
VM with one class loader. So if you have a suite of tests that test different
services, each of which might be using a different version of the common data
model, then the first service executed loads the common data model, which 
really isn&amp;#8217;t exactly common. This causes tests to fail that would not fail
if each text executed with its own class loader.&lt;/p&gt;


	&lt;p&gt;Rather than deal with writing custom class loaders, Bob instead make it 
possible to name a VM (see the title for the syntax). By doing this, Bob
make it possible to effect a similar environment to that experienced by &lt;span class="caps"&gt;EJB&lt;/span&gt;&amp;#8217;s by default.&lt;/p&gt;</description>
      <pubDate>Wed, 04 Mar 2009 04:07:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:4111f3d3-5049-47f4-9649-56b586e7df6b</guid>
      <author>Brett Schuchert</author>
      <link>http://blog.objectmentor.com/articles/2009/03/04/define-test_system-fit-a-part-ii</link>
      <category>Schuchert's Scattered Synapses </category>
      <category>ejb</category>
      <category>class</category>
      <category>loading</category>
      <category>acceptnace</category>
      <category>testing</category>
    </item>
  </channel>
</rss>

