Test does not read process.xml

I was writing an integration test for authorization, which did not work for me, because StandaloneInMemoryTestConfiguration does not reflect settings from process.xml nor application.yaml.

  • Is it on purpose?
  • Is there any way how to force Camunda to read it?

So far, I use this

@Deployment(resources = "bpmn/sample.bpmn")
public class SampleProcessTest extends AbstractProcessEngineRuleTest {

    @Test
    public void authorization() {
        autoMock("bpmn/sample.bpmn");
        processEngine.getProcessEngineConfiguration().setAuthorizationEnabled(true);
       //...
    }
}

But it does not test the process.xml configuration itself and moreover it turns on authorization for all test cases, not possible to turn it off again.

1 Like

Hi @banterCZ,

it’s not clear how you configure Camunda in general.

  1. Are you using process application? This is where processes.xml comes into play. You can check this tests camunda-bpm-platform/engine/src/test/java/org/camunda/bpm/application/impl/embedded/EmbeddedProcessApplicationTest.java at master · camunda/camunda-bpm-platform · GitHub
  2. Are you using Spring Boot Starter? This is where application.yaml is used.
  3. Are you using Spring plugin and process applications? If yes, you can just create Process application class with such annotation:

@ProcessApplication(deploymentDescriptors={“path to processes.xml”})

and declare it on your application context.

2 Likes

I started with https://github.com/camunda/camunda-bpm-spring-boot-starter/tree/2.2.0/examples/example-simple I tried to define authorization in the yaml, but it did not work.

EmbeddedProcessApplicationTest looks like JUnit 3.

I will try @ProcessApplication

I have ended with this solution.

@RunWith(SpringRunner.class)
@SpringBootTest
public class AuthorizationSampleProcessTest {

    @Autowired
    private IdentityService identityService;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private AuthorizationService authorizationService;

    public void authorization() {

        final Authorization createProcessInstanceAuthorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
        createProcessInstanceAuthorization.setUserId("frederik");
        createProcessInstanceAuthorization.setResourceId("*");
        createProcessInstanceAuthorization.setResource(Resources.PROCESS_INSTANCE);
        createProcessInstanceAuthorization.addPermission(Permissions.CREATE);
        authorizationService.saveAuthorization(createProcessInstanceAuthorization);

        final Authorization createProcessDefinitionAuthorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
        createProcessDefinitionAuthorization.setUserId("frederik");
        createProcessDefinitionAuthorization.setResourceId("*");
        createProcessDefinitionAuthorization.setResource(Resources.PROCESS_DEFINITION);
        createProcessDefinitionAuthorization.addPermission(Permissions.CREATE_INSTANCE);
        authorizationService.saveAuthorization(createProcessDefinitionAuthorization);
        identityService.setAuthenticatedUserId("frederik");

        runtimeService.startProcessInstanceByKey("Sample");
    }

    @Test(expected = AuthorizationException.class)
    public void authorization_fail() {
        identityService.setAuthenticatedUserId("joe");
        runtimeService.startProcessInstanceByKey("Sample");
    }

}

And this configuration application.yaml

spring.application.name: simpleApplication
spring:
  datasource:
    url: jdbc:h2:mem:example-simple;MODE=Oracle;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
camunda:
  bpm:
    appl  ication:
      isDeleteUponUndeploy: false
      isScanForProcessDefinitions: false
      isDeployChangedOnly: true
      isResumePreviousVersions: true
      resumePreviousBy: a value
    job-execution:
      enabled: true
    metrics:
      enabled: false
      db-reporter-activate: false
    authorization:
      enabled: true
2 Likes