I’m trying to implement a simple example, with a service task that invokes a delegate expression. I’m able to get the task to work when implemented as a Java class, but not as a delegate expression.
I get the following error: ENGINE-02033 Delegate Expression ‘createTweetDelegate’ did neither resolve to an implementation of ‘interface org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior’ nor ‘interface org.camunda.bpm.engine.delegate.JavaDelegate’.
The task in review-tweet.bpmn:
<bpmn:serviceTask id="Activity_0n37fh2" name="Publish tweet" camunda:delegateExpression="createTweetDelegate">
I’ve also tried using the full path with the package name, like this:
<bpmn:serviceTask id="Activity_0n37fh2" name="Publish tweet" camunda:delegateExpression="com.camunda.training.createTweetDelegate">
In CreateTweetDelegate.java:
@Component(value="createTweetDelegate")
public class CreateTweetDelegate implements JavaDelegate {
private final Logger LOGGER = LoggerFactory.getLogger(CreateTweetDelegate.class.getName());
public void execute(DelegateExecution execution) throws Exception {
String content = (String) execution.getVariable("content");
LOGGER.info("Publishing tweet: " + content);
AccessToken accessToken = new AccessToken("220324559-YfhutOgjLKsgPFXGGkda4q72rfeEp2nprXZHDTQf", "QmlH4CUdDDav3u2rrE2MQCmWwKfVHkcc8qlGpu6SMn0uD");
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer("XSQGUIOwiOs8p55NMijlObpPu", "ZXDVbURd1WMUFBmygQ4Je8PPR0gkaKwczkgQ6YfgPfF0MYnIzY");
twitter.setOAuthAccessToken(accessToken);
twitter.updateStatus(content);
}
}
In CamundaApplication.java:
@SpringBootApplication
@EnableProcessApplication("twitter-qa")
public class CamundaApplication {
public static void main(String... args) {
SpringApplication.run(CamundaApplication.class, args);
}
}
The unit test that fails:
@ExtendWith(ProcessEngineCoverageExtension.class)
public class ProcessJUnitTest {
@Test
@Deployment(resources = "review-tweet.bpmn")
public void testHappyPath() {
// Create a HashMap to put in variables for the process instance
Map<String, Object> variables = new HashMap<String, Object>();
int randomNumber = (int)Math.floor(Math.random()*(10000));
variables.put("content", "Exercise 4 test - D" + randomNumber);
variables.put("approved", true);
// Start process with Java API and variables
ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("review-tweet", variables);
// Make assertions on the process instance
assertThat(processInstance).isEnded();
}
}