Write tests
See Testing ALFA policies for in depth instructions.
Once your use cases and attribute dictionaries are defined, you can begin writing tests.
Start by deleting the existing example tests that came pre-populated with the APD distribution located under
src/test/java/.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.javaimport 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())));noteThe Dictionary class in the APD package contains the attribute constants generated automatically when you run the
generateJavaDictionaryFromYamlGradle task.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.