Issue with @Value using JUnit 5

I am using JUnit 5 with some extensions, and test is running by calling bpmn, and relevant delegate expression. However, @Value variables in delegate coming as ‘null’.
Below is my code snippet,

Test Class
@SpringBootTest
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(ProcessEngineExtension.class)
@TestPropertySource(locations=“classpath:application-test.yml”)
@ActiveProfiles(“test”)
public class ProcessTest {

@Mock
EntryIDStartListener entryIDStartListener;

@Rule
public ProcessEngineRule rule = new ProcessEngineRule();

@Before
public void setUp() throws IOException {
    MessageList.messages = new MessageLoader().getFileContent(new String[]{"classpath*:/requests/*.*", "classpath*:/responses/*.*"});
    ReflectionTestUtils.setField(entryIDStartListener, "applicationID", "asdfadsf");
    MockitoAnnotations.initMocks(this);
}

@Test
@Deployment(resources = {"bpm/NCTOFulfilment.bpmn", "bpm/PromoteCustomer.bpmn", "bpm/BusinessBC.bpmn"})
public void testFlow() throws Exception {
    String message = MessageList.getMessage("flowInputRequest");
    Map<String, Object> inputMap = new Gson().fromJson(message, Map.class);
    String businessKey = (String) inputMap.get(Enums.KVK_NUMBER.getValue());
    ProcessInstance nctoFulfilmentInstance = runtimeService().startProcessInstanceByKey("NCTOFulfilment", businessKey, inputMap);
    assertThat(nctoFulfilmentInstance).isActive();
    assertThat(nctoFulfilmentInstance).isStarted();
    assertThat(nctoFulfilmentInstance).hasNotPassed("NCTOFulfillment_Start");
    execute(job());

    assertThat(nctoFulfilmentInstance)
            .hasPassed("NCTOFulfillment_Start")
            .hasPassed("PromoteCustomerGateway");
    execute(job());

    ProcessInstance promoteCustomerCallActivityInst = calledProcessInstance(nctoFulfilmentInstance);
    assertThat(promoteCustomerCallActivityInst)
            .isActive()
            .hasPassed("PromoteCustemer_Start");

    ProcessInstance businessBCCallActivityInst = calledProcessInstance(promoteCustomerCallActivityInst);
    assertThat(businessBCCallActivityInst)
            .isActive()
            .hasPassed("BusinessBC_Start");

    assertThat(businessBCCallActivityInst).isWaitingAt("EntryIDActivity");
    execute(job());

    assertThat(businessBCCallActivityInst).hasPassed("EntryIDActivity");
}

}

Delegate Class
@Component(“entryIDStartListener”)
@Slf4j
public class EntryIDStartListener extends AbstractNctoFulfillment {

@Value("${application.apis.soap.promote_customer.entry_id.url}")
private String url;

@Value("${application.apis.soap.static_header.applicationID}")
private String applicationID;

@Value("${application.apis.soap.static_header.sessionID}")
private String sessionID;

@Value("${application.apis.soap.static_header.userID}")
private String userID;

@Value("${application.task.retryCycle}")
private String retryCycle;

…}

Any idea what I am missing here?

Do not worry @pramod_Rajane - help is on the way!
Tagging @Ingo_Richtsmeier in this question here because he is for sure the best JUnit 5 expert I know. :wink:
Do you have any idea?

Hi @pramod_Rajane,

I see that you mix the Junit4 Rule with Junit5 @ExtendWith() annotation and the @SpringBootTest.

I don’t know which concept wins in such a mix.

First decide, what kind of tests do you want to write:

  • Unit tests with an embedded engine (without Spring beans) or
  • Integration tests where the engine is started from the Spring boot application and injected in your test class?

Let me know what you want. Then it’s easier to sort out the details.

Hope this helps, Ingo

1 Like

I have modified to second approach, i.e, Integration test.
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles(“test”)

I am able to populate @values, however one observation,
my test case sometime getting succeeded, sometime failing with below exception

org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of ‘DELETE MessageEntity[c3dce37a-c563-11ec-af72-0050569198c3]’ failed. Entity was updated by another transaction concurrently.

How to handle this inconsistent exception?