vernac / architecture, expressed.
Browse documentation

Start a usecase scenario from a configured fixture

In Vernac 0.7.0, a suite with using can bind an existing Spring bean by its declared Vernac type. Add named "beanName" when several beans share that type. The compiler checks the type of every argument. Spring reports missing or ambiguous beans at the fixture statement. The Spring context is scoped to one scenario. A TenantId bean still establishes the tenant scope, and a scenario may also bind it explicitly.

namespace example.workflow;

id WorkflowId;
value MicroEur(long amount);

usecase ActivateWorkflow(WorkflowId, MicroEur) behavior {
    execute vernac {
        require false else WorkflowGoalUnreachable.
    }
}

usecase ApproveWorkflow(WorkflowId) behavior {
    execute vernac {
        require false else AlreadyApproved.
    }
}

The Java class below is Spring test infrastructure. It supplies verified tenant context and named beans to the native scenarios.

package example.workflow;

import example.workflow.domain.WorkflowId;
import example.workflow.usecase.ActivateWorkflow;
import example.workflow.usecase.ApproveWorkflow;
import org.vernac.runtime.tenancy.TenantId;
import java.util.UUID;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration(proxyBeanMethods = false)
@Import({ActivateWorkflow.class, ApproveWorkflow.class})
public class WorkflowFixtures {
    @Bean
    TenantId tenantId() {
        return TenantId.of(UUID.fromString("00000000-0000-4000-8000-000000000003"));
    }

    @Bean
    WorkflowId blockedWorkflow() {
        return WorkflowId.of("00000000-0000-4000-8000-000000000001");
    }

    @Bean
    WorkflowId otherWorkflow() {
        return WorkflowId.of("00000000-0000-4000-8000-000000000002");
    }
}
namespace example.workflow;

suite WorkflowChecks using example.workflow.WorkflowFixtures {
    scenario unreachableGoal {
        given tenant = bean TenantId;
        expect tenant is present;
        given workflow = bean WorkflowId named "blockedWorkflow";
        given expected = WorkflowId("00000000-0000-4000-8000-000000000001");
        expect workflow equals expected;
        when invoke ActivateWorkflow(workflow, MicroEur(3000000000L)) rejects WorkflowGoalUnreachable;
        when invoke ApproveWorkflow(workflow) rejects AlreadyApproved;
        expect workflow equals expected;
    }
}

is error "CODE" compares the full exception message and requires an IllegalStateException or an IllegalArgumentException from the invoked operation. It does not unwrap causes. Use rejects Code for a native Vernac rejection, is ACCESS_DENIED for authorization and is invalid for domain validation. An expected failure cannot bind a result.