<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Objectopia &#187; Uncategorized</title>
	<atom:link href="http://objectopia.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://objectopia.com</link>
	<description></description>
	<lastBuildDate>Fri, 23 Dec 2011 12:33:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='objectopia.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Objectopia &#187; Uncategorized</title>
		<link>http://objectopia.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://objectopia.com/osd.xml" title="Objectopia" />
	<atom:link rel='hub' href='http://objectopia.com/?pushpress=hub'/>
		<item>
		<title>Weld JUnit 4 Runner</title>
		<link>http://objectopia.com/2011/05/29/weld-junit-4-runner/</link>
		<comments>http://objectopia.com/2011/05/29/weld-junit-4-runner/#comments</comments>
		<pubDate>Sun, 29 May 2011 02:18:54 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=362</guid>
		<description><![CDATA[I&#8217;ve been having a look at Weld recently and wanted to be able to try some stuff out without a container in JUnit, but couldn&#8217;t find a JUnit Runner class to do it for me. I was really suprised how simple it was: Now you can do this : Because your test class is just [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&#038;blog=8328377&#038;post=362&#038;subd=objectopia&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been having a look at <a title="Weld" href="http://seamframework.org/Weld">Weld</a> recently and wanted to be able to try some stuff out without a container in JUnit, but couldn&#8217;t find a JUnit Runner class to do it for me.</p>
<p>I was really suprised how simple it was:</p>
<p><pre class="brush: java; light: true;">
package org.objectopia.test;

import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;

import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;

public class WeldJUnit4Runner extends BlockJUnit4ClassRunner {

    private final Class klass;
    private final Weld weld;
    private final WeldContainer container;

    public WeldJUnit4Runner(final Class klass) throws InitializationError {
        super(klass);
        this.klass = klass;
        this.weld = new Weld();
        this.container = weld.initialize();
    }

    @Override
    protected Object createTest() throws Exception {
        final Object test = container.instance().select(klass).get();

        return test;
    }
}
</pre></p>
<p>Now you can do this :</p>
<p><pre class="brush: java; light: true;">
@RunWith(WeldJUnit4Runner.class)
public class PersistenceTest {

    @Inject UserRepository repository;

    ...
}
</pre></p>
<p>Because your test class is just another CDI bean, you can inject any bean reference you require.</p>
<p>This is where the power of CDI comes in to play, you can do something like this:</p>
<p><pre class="brush: java; light: true;">
    @Inject @Mock UserRepository userRepository;
</pre></p>
<p>And create a producer method to mock it out:</p>
<p><pre class="brush: java; light: true;">
    @Produces @Mock UserRepository createUserRepository() { ... }
</pre></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/362/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&#038;blog=8328377&#038;post=362&#038;subd=objectopia&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2011/05/29/weld-junit-4-runner/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
		<item>
		<title>EJB 3.0 Injecting The Correct Implementation</title>
		<link>http://objectopia.com/2009/07/24/ejb-3-0-injecting-the-correct-implementation/</link>
		<comments>http://objectopia.com/2009/07/24/ejb-3-0-injecting-the-correct-implementation/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 21:49:07 +0000</pubDate>
		<dc:creator>Chris Clark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[EJB 3.0 injection]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=222</guid>
		<description><![CDATA[When using stateless and stateful session beans I often find that I&#8217;m creating one interface per one implementation, which will be enhanced with the release of the 3.1 spec and implicit interfaces. Anyway on one of the occasions I had actually had multiple implementations of an interface that I wanted to inject, this made me [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&#038;blog=8328377&#038;post=222&#038;subd=objectopia&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When using stateless and stateful session beans I often find that I&#8217;m creating one interface per one implementation, which will be enhanced with the release of the 3.1 spec and implicit interfaces. Anyway on one of the occasions I had actually had multiple implementations of an interface that I wanted to inject, this made me stop and think how do I that!! It turns out it was pretty simple with a few annotations.</p>
<p>On your class that is implementing the interface you need to use the name attribute: -</p>
<p><pre class="brush: java;">

@Stateful(name=&quot;xxx.AssetTypeOverrideService&quot;)
public class AssetTypeOverrideService implements OverrideService{

@Stateful(name=&quot;xxxRuleTypeOverrideService&quot;)
public class RuleTypeOverrideService implements OverrideService {

</pre></p>
<p>Then on the bean you want inject these into you use:</p>
<p><pre class="brush: java;">

@EJB(beanName=&quot;xxx.AssetTypeOverrideService&quot;)
private OverrideService assetOverrideService;
	
@EJB(beanName=&quot;xxx.RuleTypeOverrideService&quot;)
private OverrideService ruleTypeOverrideService;

</pre></p>
<p>The name can be anything you want I just think it&#8217;s logical to keep it the same as the class and the beanName obviously is the same value of the bean you want to inject that has the correct implementation. </p>
<p>It seems easy now but it did make me stop and think.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/222/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&#038;blog=8328377&#038;post=222&#038;subd=objectopia&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/07/24/ejb-3-0-injecting-the-correct-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb4e8f1d97dd63efbba72b45e6130bb0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chrisclark78</media:title>
		</media:content>
	</item>
	</channel>
</rss>
