Examples

The following example constitutes a full minimal SAPL unit test:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class B_PolicyWithSimpleFunctionTest {

    private SaplTestFixture fixture;

    @BeforeEach
    void setUp() {
        fixture = new SaplUnitTestFixture("policyWithSimpleFunction.sapl");
    }

    @Test
    void test() {
        fixture.constructTestCaseWithMocks()
                .givenFunction("time.dayOfWeek", Val.of("SATURDAY"), times(1))
                .when(AuthorizationSubscription.of("willi", "read", "something"))
                .expectPermit()
                .verify();
    }
}

A lot of additional examples showcasing the various features of this SAPL test framework can be found in the demo project here.