Skip to main content

The most recent patch for this version is 26.1.6.  Learn more  

Version: 26.1

Write tests

tip

See Testing ALFA policies for in depth instructions.

Once your use cases and attribute dictionaries are defined, you can begin writing tests.

  1. Start by deleting the existing example tests that came pre-populated with the APD distribution located under src/test/java/.

  2. Create a new Java class under your test package (e.g., src/test/java/com/acme/MyTest.java). You can use the following template as a starting point:

    /src/test/java/com/acme/MyTest.java
    import org.junit.jupiter.api.extension.RegisterExtension;
    import com.axiomatics.cr.alfa.test.junit.AlfaExtension;
    import apd.Dictionary.*;

    import java.util.Dictionary;

    public class MyTest {

    @RegisterExtension
    public AlfaExtension alfa = new AlfaExtension();

    @Test
    public void shouldNotPermitConsultantsToApprove() {
    TestResponse result = target.newTestRequest()
    .with(Dictionary.USER_ROLE, "consultant")
    .with(Dictionary.ACTION, "approve")
    .evaluate();

    assertThat(result, is(not(permit())));
    note

    The Dictionary class in the APD package contains the attribute constants generated automatically when you run the generateJavaDictionaryFromYaml Gradle task.

  3. If you run the test now, it should compile successfully but fail during execution. This failure is expected because the underlying policies have not yet been implemented.

Proceed to the next section to begin writing your ALFA policies.