Hi Alfonso.
I think it makes very much sense if you try to mock out the real service EJB‘s – as you keep the tests much easier and need less infrastructure. See my proposed new image for testing scopes in https://app.camunda.com/jira/browse/CAM-2116 - we already work with this one for quite a while in consulting and have good experience with it. So in that image you try to keep in scope 1.
Then Mockito is a good way to go to mock out the EJB’s or real services you need. You just need a mechanism to inject the mocks in your JavaDelegates. That depend a bit on your infrastructure (DI-Container? Spring, CDI, …?) – but is most of the time doable without Arquillian or the like.
Cheers
Bernd
--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/9305f1c9-0a8c-428b-b463-b355c000d484%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Do you use CDI named beans as delegateExpressions?
Or how to you hook in the delegates in the BPMN.xml?
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/d4b2a45d-b347-48bd-a1e8-fa234e3fd626%40googlegroups.com.
Hi Alfonso.
Then you already have the problem of how to run a JUnit Test without CDI – correct? How did you solve this?
I think there are three basic ways of doing this (if we do not use Arquillian):
- Start a CDI container for your tests (e.g. JBoss Weld)
- Start some testing lightweight CDI container (e.g. http://needle.spree.de/)
- Using the camunda mocking facility
For the third way you can call “Mocks.register(“myCdiBean”, someObject)”. In this case you can hand in the delegates from the test case and do the injection of Mocks yourself there. Make sure you add the MockExpressionManager to your ProcessEngineCOnfiguration (typed from my head – name might be a bit different).
The last one has the advantage that you do not need any environment. And you can do mocking really easy. But if you have too much delegates it might get a bit unhandy – so using a CDI container might be an option.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/1540f89e-3903-43e2-b02d-85601ce63421%40googlegroups.com.
OK great!
Just add a „setMyBusinessLogicEjb“ method and fill that from your test case before setting the Mock. Or use a reflection helper in the test case if you don’t want to have the setters…
Von: camunda-...@googlegroups.com [mailto:camunda-...@googlegroups.com] Im Auftrag von Alfonso Mateos Alarcón
Gesendet: Donnerstag, 28. August 2014 09:13
An: camunda-...@googlegroups.com
Betreff: Re: [camunda-bpm-users] How to Test individual JavaDelegate Tasks?
Hi Bernd,
--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/39276c9c-361f-421c-9074-7a0eaecce10f%40googlegroups.com.
Hi Bernd do Camunda Mocks have something like @InjectMocks of Mockito, or should I manually assign every single mock to every single inner field of my JavaDelegate? That annotation does the "magic" and assign thru reflection the inner beans that have been told to be a Mock, as told at:
http://stackoverflow.com/questions/16467685/difference-between-mock-and-injectmocks
@Mock creates a mock. @InjectMocks creates an instance of the class and injects the mocks that are created with the @Mock (or @Spy) annotations into this instance. Note that you must use @RunWith(MockitoJUnitRunner.class) or Mockito.initMocks(this) to initialise these mocks and inject them.
@RunWith(MockitoJUnitRunner.class)
public class SomeManagerTest {
@InjectMocks
private SomeManager someManager;
@Mock
private SomeDependency someDependency; // this will be injected into someManager
//tests...
}// Register mock for internal bean
MyBusinessLogicEjb myBusinessLogicEjb = new ExternalBeanMock();
Mocks.register("myBusinessLogicEjb", myBusinessLogicEjb);
StorePDFDelegate mock = new StorePDFDelegate();
Mocks.register("archiveService", mock);
final Field field = mock.getClass().getDeclaredField("myBusinessLogicEjb");
field.setAccessible(true);
field.set(mock, myBusinessLogicEjb);
I still have one question: I'm registering the real JavaDelegate class as a Mock, because I don't figure out how to get the in-memory test to instantiate my cdi delegate expression... do you figure out how to avoid mocking it? I still would mock the inner "myBusinessLogicEjb" bean...
Thanks in advance!
Hi Alfonso.
Looks good! You could now use Mockito to mock the MyBusinessLogicEjb
I'm registering the real JavaDelegate class as a Mock
But that’s exactly what you want to do – no? Maybe the name “Mock” is not completely correct here – but you create the JavaDelegate instance yourself (instead of the CDI container) and hand it over to the process engine to use it with the given name. Exactly what you want.
Von: camunda-...@googlegroups.com [mailto:camunda-...@googlegroups.com] Im Auftrag von Alfonso Mateos Alarcón
Gesendet: Donnerstag, 28. August 2014 12:29
An: camunda-...@googlegroups.com
Betreff: Re: [camunda-bpm-users] How to Test individual JavaDelegate Tasks?
Bernd, I finally got it working as you suggested, via reflection:
--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/fdec9d95-7e39-4384-a599-e6500992c942%40googlegroups.com.
This is in fact the very usecase we build the camunda-bpm-needle extension for. Check out https://github.com/camunda/camunda-bpm-needle. It's already very stable and we have been using it in a client project for a year now.
Basically, it combines the processRule for setting up the engine and the needle4j (formerly needle) rule for mocking dependencies. Needles trick is, that it injects a mock whereever you did not specify anything else. Have a look at the examples and feel free to come back to me if you need more information.
Hopefully, we will get a1.0 release at the comminty day in september, there is just some documentation missing.
Regards
Jan
I had a look to Needle4j and it looks good. It seems to use @Mock and @ObjectUnderTest annotations. But I wanted to ask you how would you face this situation I will expose to you, to know if I understand it right.
Let's suppose we have a process wich calls a serviceTask JavaDelegate, and then this JavaDelegate has some CDI injects from some other beans which execute some business logic:
@Named("serviceTask)
public class MyServiceTask implements JavaDelegate {
@Inject BusinessLogicBean businessLogicBean;
public void execute (Execution execution) {
...
businessLogicBean.someMethod(...)
...
I'd like to test the real code inside MyServiceTask, but mock the code inside BusinessLogicBean. How would the test look like? Something like this?
@Mock BusinessLogicBean businessLogicBean;
@ObjectUnderTest MyServiceTask serviceTask;
@Test
@Deployment(resources = "test-process.bpmn")
public void should_deploy_and_start_process_via_starter_bean() {
Mocks.register("serviceTask", serviceTask);
...
}
Hi Jan.
I am in favor of using the real JavaDelegate as I consider it part of the process model (logically) and mock the service only. This way you can test the whole process model with data mapping in one go without external service dependencies. And I don’t see a major downside of it.
Cheers
Bernd
Von: camunda-...@googlegroups.com [mailto:camunda-...@googlegroups.com] Im Auftrag von Jan Galinski
Gesendet: Montag, 1. September 2014 10:23
An: camunda-...@googlegroups.com
Cc: gcal...@gmail.com
Betreff: Re: [camunda-bpm-users] How to Test individual JavaDelegate Tasks?
Yes, this is how you could do it (and would if you had to mock complex behavior).
--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/0d986bcd-81eb-470e-8211-859b3edcfe2f%40googlegroups.com.