dependency injection - Java Weld CDI alternative Factory -


A factory to me in my production code, the factory should be fun in my test code. I have to apply to both the interface, which factories:

  public interface FtpTransferFactory {FtpTransfer createFtpTransfer (string host, string machine); }   

Production code: default public class implements FtpTransferFactoryImpl FtpTransferFactory {public FtpTransferFactoryImpl () {} @ Override public FtpTransfer createFtpTransfer (final String host, final String Machine) {return new FTP transfers ( ); // some real FTP transfer object}}

Test code:

  @Alternative implements public square FtpTransferFactoryTestImpl FtpTransferFactory {@Override public FtpTransfer createFtpTransfer (String host , String machine) {return ...; // Some real FTP transfer objects, with different settings (test env)}}   

Beans located on soya / test / resources. In XML:

  & lt; Options & gt; & Lt; Classes & gt; Engine.FtpTransferFactoryTestImpl & lt; / Square & gt; & Lt; / Options & gt;   

apply my class:

  @Default public square SomeClass / ** FTP Factory * / @Default @Inject private FtpTransferFactory ftpFactory; ...}   

When I execute my unit, my implementation class still ends with the production factory instead of the factory. However, when I put the element in my source / main / resources (output) it works, but I do not want that since I am putting the test code in the output code. I have done many tutorials through this tutorial ... Am I doing wrong?

src / main / resources and src / test / resources In the class there are two separate bean deployment archives (BDA). A beans.xml descriptor only affects the current BDA

Then your . & Lt; Options & gt; Definition Only your test classes affect your production classes, but not

If you use CDI 1.1, you can alternate global (ie activate all BDAs in your application) a adding @Priority annotation.

At CDI 1.0, you could try to override your default bean instead of @Always > @Specializes

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -