I have been mocking out some seam components using the following signature:
@Name("myService")
@Install(debug = true, precedence = Install.MOCK)
public class MyServiceMock implements MyService
I enable my mocks by changing this line in my components.xml
<core:init transaction-management-enabled="false" />
to this:
<core:init transaction-management-enabled="false" debug="true" />
This was fine when I wanted to mock out all of the classes. I just had my ant script replace my normal components.xml with a debug version.
Is there any way to conditionally mock out one or more components? An ideal solution would allow me to specify which components to mock out in an external file such as components.properties or another properties file.
My Solution
Here's what I settled on based on germanescobar's answer.
I changed my mock component signatures to match this:
@Name("myService")
@Install(false)
public class MyServiceMock implements MyService
Then I added a line for each component I want to mock out to components.xml that looks like this:
<component name="myService" installed="false" precedence="40"
class="com.foo.bar.baz.service.MyServiceMock" />
To enable a mock, I set installed=true
.