text:
package com.evolveum.midpoint.model.intest.rbac;

import javax.xml.datatype.XMLGregorianCalendar;

import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

/**
 * @author semancik
 *
 */
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestAssignmentValidity extends AbstractRbacTest {

    private XMLGregorianCalendar jackPirateValidTo;

    @Override
    public void initSystem(Task initTask, OperationResult initResult)
            throws Exception {
        super.initSystem(initTask, initResult);
//        InternalsConfig.setTestingPaths(TestingPaths.REVERSED);
    }

    /**
     * MID-4110
     */
    @Test
    public void test100JackAssignRolePirateValidTo() throws Exception {
        final String TEST_NAME = "test100JackAssignRolePirateValidTo";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, activationType, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertModifyMetadata(userAfter, startTs, endTs);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.ENABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();
    }

    /**
     * Assignment expires.
     * MID-4110, MID-4114
     */
    @Test
    public void test102Forward15min() throws Exception {
        final String TEST_NAME = "test102Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * New assignment. No time validity.
     * MID-4110
     */
    @Test
    public void test104JackAssignRolePirateAgain() throws Exception {
        final String TEST_NAME = "test104JackAssignRolePirateAgain";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertModifyMetadata(userAfter, startTs, endTs);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();
    }

    /**
     * Unassign valid assignment. Only invalid assignment remains.
     * MID-4110
     */
    @Test
    public void test106JackUnassignRolePirateValid() throws Exception {
        final String TEST_NAME = "test106JackUnassignRolePirateValid";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        displayWhen(TEST_NAME);
        unassignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * MID-4110
     */
    @Test
    public void test109JackUnassignAll() throws Exception {
        unassignAll("test109JackUnassignAll");
    }

    /**
     * Raw modification of assignment. The assignment is not effective immediately,
     * as this is raw operation. So, nothing much happens. Yet.
     * MID-4110
     */
    @Test
    public void test110JackAssignRolePirateValidToRaw() throws Exception {
        final String TEST_NAME = "test110JackAssignRolePirateValidToRaw";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        ModelExecuteOptions options = ModelExecuteOptions.createRaw();

        // WHEN
        displayWhen(TEST_NAME);
        modifyUserAssignment(USER_JACK_OID, ROLE_PIRATE_OID, RoleType.COMPLEX_TYPE, null,
                task, null, activationType, true, options, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentTypeAfter, null);
        assertRoleMembershipRef(userAfter);
        assertDelegatedRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * MID-4110, MID-4114
     */
    @Test
    public void test111RecomputeJack() throws Exception {
        final String TEST_NAME = "test111RecomputeJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.ENABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();
    }

    /**
     * Assignment expires.
     * MID-4110, MID-4114
     */
    @Test
    public void test112Forward15min() throws Exception {
        final String TEST_NAME = "test102Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * New assignment. No time validity.
     * MID-4110
     */
    @Test
    public void test114JackAssignRolePirateAgain() throws Exception {
        final String TEST_NAME = "test114JackAssignRolePirateAgain";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertModifyMetadata(userAfter, startTs, endTs);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test119JackUnassignAll() throws Exception {
        unassignAll("test119JackUnassignAll");
    }

    /**
     * Sailor is an idempotent(conservative) role.
     * MID-4110
     */
    @Test
    public void test120JackAssignRoleSailorValidTo() throws Exception {
        final String TEST_NAME = "test120JackAssignRoleSailorValidTo";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, activationType, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertModifyMetadata(userAfter, startTs, endTs);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.ENABLED);
        assertRoleMembershipRef(userAfter, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummySailorAccount();
    }

    /**
     * Assignment expires.
     * MID-4110, MID-4114
     */
    @Test
    public void test122Forward15min() throws Exception {
        final String TEST_NAME = "test122Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * New assignment. No time validity.
     * MID-4110
     */
    @Test
    public void test124JackAssignRoleSailorAgain() throws Exception {
        final String TEST_NAME = "test124JackAssignRoleSailorAgain";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertModifyMetadata(userAfter, startTs, endTs);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummySailorAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test129JackUnassignAll() throws Exception {
        unassignAll("test129JackUnassignAll");
    }

    /**
     * Raw modification of assignment. The assignment is not effective immediately,
     * as this is raw operation. So, nothing much happens. Yet.
     * MID-4110
     */
    @Test
    public void test130JackAssignRoleSailorValidToRaw() throws Exception {
        final String TEST_NAME = "test130JackAssignRoleSailorValidToRaw";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        ModelExecuteOptions options = ModelExecuteOptions.createRaw();

        // WHEN
        displayWhen(TEST_NAME);
        modifyUserAssignment(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, RoleType.COMPLEX_TYPE, null,
                task, null, activationType, true, options, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, null);
        assertRoleMembershipRef(userAfter);
        assertDelegatedRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * MID-4110, MID-4114
     */
    @Test
    public void test131RecomputeJack() throws Exception {
        final String TEST_NAME = "test131RecomputeJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.ENABLED);
        assertRoleMembershipRef(userAfter, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummySailorAccount();
    }

    /**
     * Assignment expires.
     * MID-4110, MID-4114
     */
    @Test
    public void test132Forward15min() throws Exception {
        final String TEST_NAME = "test132Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * New assignment. No time validity.
     * MID-4110
     */
    @Test
    public void test134JackAssignRoleSailorAgain() throws Exception {
        final String TEST_NAME = "test134JackAssignRoleSailorAgain";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertModifyMetadata(userAfter, startTs, endTs);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummySailorAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test139JackUnassignAll() throws Exception {
        unassignAll("test139JackUnassignAll");
    }

    /**
     * This time do not recompute. Just set everything up, let the assignment expire
     * and assign the role again.
     * MID-4110
     */
    @Test
    public void test140JackAssignRoleSailorValidToRaw() throws Exception {
        final String TEST_NAME = "test140JackAssignRoleSailorValidToRaw";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        ModelExecuteOptions options = ModelExecuteOptions.createRaw();

        // WHEN
        displayWhen(TEST_NAME);
        modifyUserAssignment(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, RoleType.COMPLEX_TYPE, null,
                task, null, activationType, true, options, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, null);
        assertRoleMembershipRef(userAfter);
        assertDelegatedRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * Assignment expires. BUt do NOT recompute.
     * MID-4110
     */
    @Test
    public void test142Forward15min() throws Exception {
        final String TEST_NAME = "test142Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);

        // WHEN
        displayWhen(TEST_NAME);
        clockForward("PT15M");
        // do NOT recompute

        // THEN
        displayThen(TEST_NAME);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, null); // Not recomputed
        assertRoleMembershipRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * New assignment. No time validity.
     * MID-4110
     */
    @Test
    public void test144JackAssignRoleSailorAgain() throws Exception {
        final String TEST_NAME = "test144JackAssignRoleSailorAgain";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertModifyMetadata(userAfter, startTs, endTs);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummySailorAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test149JackUnassignAll() throws Exception {
        unassignAll("test149JackUnassignAll");
    }

    /**
     * MID-4110
     */
    @Test
    public void test150JackAssignRolePirate() throws Exception {
        final String TEST_NAME = "test150JackAssignRolePirate";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);

        assertAssignments(userAfter, 1);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);

        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();
    }

    /**
     * Sailor is an idempotent(conservative) role.
     * MID-4110
     */
    @Test
    public void test151JackAssignRoleSailorValidTo() throws Exception {
        final String TEST_NAME = "test151JackAssignRoleSailorValidTo";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, activationType, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);

        assertAssignments(userAfter, 2);
        AssignmentType assignmentSailorTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentSailorTypeAfter, ActivationStatusType.ENABLED);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);

        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateSailorAccount();
    }

    /**
     * Assignment expires.
     * MID-4110, MID-4114
     */
    @Test
    public void test153Forward15min() throws Exception {
        final String TEST_NAME = "test153Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);
        AssignmentType assignmentSailorTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentSailorTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);

        assertJackDummyPirateAccount();
    }

    /**
     * New assignment. No time validity.
     * MID-4110
     */
    @Test
    public void test154JackAssignRoleSailorAgain() throws Exception {
        final String TEST_NAME = "test154JackAssignRoleSailorAgain";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 3);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateSailorAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test159JackUnassignAll() throws Exception {
        unassignAll("test159JackUnassignAll");
    }

    /**
     * MID-4110
     */
    @Test
    public void test160JackAssignRolePirate() throws Exception {
        final String TEST_NAME = "test160JackAssignRolePirate";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);

        assertAssignments(userAfter, 1);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);

        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test161JackAssignRoleSailorValidToRaw() throws Exception {
        final String TEST_NAME = "test161JackAssignRoleSailorValidToRaw";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        ModelExecuteOptions options = ModelExecuteOptions.createRaw();

        // WHEN
        displayWhen(TEST_NAME);
        modifyUserAssignment(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, RoleType.COMPLEX_TYPE, null,
                task, null, activationType, true, options, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);

        assertAssignments(userAfter, 2);
        AssignmentType assignmentSailorTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentSailorTypeAfter, null);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);

        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID); // SAILOR is not here, we are raw
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();
    }

    /**
     * Recompute should fix it all.
     * MID-4110
     */
    @Test
    public void test162RecomputeJack() throws Exception {
        final String TEST_NAME = "test162RecomputeJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        // WHEN
        displayWhen(TEST_NAME);
        reconcileUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);

        assertAssignments(userAfter, 2);
        AssignmentType assignmentSailorTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentSailorTypeAfter, ActivationStatusType.ENABLED);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);

        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateSailorAccount();
    }

    /**
     * Assignment expires.
     * MID-4110, MID-4114
     */
    @Test
    public void test163Forward15min() throws Exception {
        final String TEST_NAME = "test163Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);
        AssignmentType assignmentSailorTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentSailorTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);

        assertJackDummyPirateAccount();
    }

    /**
     * New assignment. No time validity.
     * MID-4110
     */
    @Test
    public void test164JackAssignRoleSailorAgain() throws Exception {
        final String TEST_NAME = "test164JackAssignRoleSailorAgain";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 3);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateSailorAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test169JackUnassignAll() throws Exception {
        unassignAll("test169JackUnassignAll");
    }

    /**
     * MID-4110
     */
    @Test
    public void test170JackAssignRolePirate() throws Exception {
        final String TEST_NAME = "test170JackAssignRolePirate";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);

        assertAssignments(userAfter, 1);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);

        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test171JackAssignRoleWeakSingerValidTo() throws Exception {
        final String TEST_NAME = "test171JackAssignRoleWeakSingerValidTo";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_WEAK_SINGER_OID, activationType, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);

        assertAssignments(userAfter, 2);
        AssignmentType assignmentSingerTypeAfter = assertAssignedRole(userAfter, ROLE_WEAK_SINGER_OID);
        assertEffectiveActivation(assignmentSingerTypeAfter, ActivationStatusType.ENABLED);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);

        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID, ROLE_WEAK_SINGER_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateSingerAccount();
    }

    /**
     * Assignment expires.
     * MID-4110, MID-4114
     */
    @Test
    public void test173Forward15min() throws Exception {
        final String TEST_NAME = "test173Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        AssignmentType assignmentPirateTypeAfter = assertAssignedRole(userAfter, ROLE_PIRATE_OID);
        assertEffectiveActivation(assignmentPirateTypeAfter, ActivationStatusType.ENABLED);
        AssignmentType assignmentSailorTypeAfter = assertAssignedRole(userAfter, ROLE_WEAK_SINGER_OID);
        assertEffectiveActivation(assignmentSailorTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);

        // Dummy attribute "title" is tolerant, so the singer value remains
        assertJackDummyPirateSingerAccount();
    }

    /**
     * New assignment. No time validity.
     * MID-4110
     */
    @Test
    public void test174JackAssignRoleSingerAgain() throws Exception {
        final String TEST_NAME = "test174JackAssignRoleSingerAgain";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_WEAK_SINGER_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 3);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID, ROLE_WEAK_SINGER_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateSingerAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test179JackUnassignAll() throws Exception {
        unassignAll("test179JackUnassignAll");
    }

    /**
     * This time do both assigns as raw. And do NOT recompute until everything is set up.
     * MID-4110
     */
    @Test
    public void test180JackAssignRoleSailorValidToRaw() throws Exception {
        final String TEST_NAME = "test180JackAssignRoleSailorValidToRaw";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        // WHEN
        displayWhen(TEST_NAME);
        modifyUserAssignment(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, RoleType.COMPLEX_TYPE, null,
                task, null, activationType, true, ModelExecuteOptions.createRaw(), result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, null);
        assertRoleMembershipRef(userAfter);
        assertDelegatedRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * MID-4110
     */
    @Test
    public void test182Forward15minAndAssignRaw() throws Exception {
        final String TEST_NAME = "test142Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        modifyUserAssignment(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, RoleType.COMPLEX_TYPE, null,
                task, null, null, true, ModelExecuteOptions.createRaw(), result);

        // THEN
        displayThen(TEST_NAME);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    /**
     * MID-4110, MID-4114
     */
    @Test
    public void test184RecomputeJack() throws Exception {
        final String TEST_NAME = "test184RecomputeJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_STRONG_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummySailorAccount();
    }

    /**
     * MID-4110
     */
    @Test
    public void test189JackUnassignAll() throws Exception {
        unassignAll("test189JackUnassignAll");
    }

    /**
     * Preparation for MID-4198 "Disabled assignments project value in certain cases"
     */
    @Test
    public void test200JackAssignCurrentPirateFutureSailor() throws Exception {
        final String TEST_NAME = "test200JackAssignCurrentPirateFutureSailor";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        activationType.setValidFrom(getTimestamp("P1M"));

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);
        assignRole(USER_JACK_OID, ROLE_STRONG_SAILOR_OID, activationType, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();     // no sailor!
    }

    /**
     * MID-4198 "Disabled assignments project value in certain cases"
     */
    @Test
    public void test202RecomputeJack() throws Exception {
        final String TEST_NAME = "test202RecomputeJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();     // still there should be no sailor
    }

    /**
     * MID-4198 "Disabled assignments project value in certain cases"
     */
    @Test
    public void test204ReconcileJack() throws Exception {
        final String TEST_NAME = "test204ReconcileJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        reconcileUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();     // still there should be no sailor
    }

    @Test
    public void test209JackUnassignAll() throws Exception {
        unassignAll("test209JackUnassignAll");
    }

    /**
     * The same as test200-204 but with ROLE_STRONG_RICH_SAILOR
     *
     * Preparation for MID-4198 "Disabled assignments project value in certain cases"
     */
    @Test
    public void test210JackAssignCurrentPirateFutureRichSailor() throws Exception {
        final String TEST_NAME = "test210JackAssignCurrentPirateFutureRichSailor";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        activationType.setValidFrom(getTimestamp("P1M"));

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);
        assignRole(USER_JACK_OID, ROLE_STRONG_RICH_SAILOR_OID, activationType, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_RICH_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();     // no sailor!
    }

    /**
     * MID-4198 "Disabled assignments project value in certain cases"
     */
    @Test
    public void test212RecomputeJack() throws Exception {
        final String TEST_NAME = "test212RecomputeJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();     // still there should be no sailor
    }

    /**
     * MID-4198 "Disabled assignments project value in certain cases"
     */
    @Test
    public void test214ReconcileJack() throws Exception {
        final String TEST_NAME = "test214ReconcileJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        reconcileUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateAccount();     // still there should be no sailor
    }

    @Test
    public void test219JackUnassignAll() throws Exception {
        unassignAll("test219JackUnassignAll");
    }

    /**
     * Just verifying that account presence honors assignment validity (checked as part of MID-4199 evaluation)
     */
    @Test
    public void test220JackAssignFutureRichSailor() throws Exception {
        final String TEST_NAME = "test220JackAssignFutureRichSailor";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        unassignAll(TEST_NAME);

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        activationType.setValidFrom(getTimestamp("P1M"));

        // WHEN
        displayWhen(TEST_NAME);
        assignRole(USER_JACK_OID, ROLE_STRONG_RICH_SAILOR_OID, activationType, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_RICH_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter);
        assertDelegatedRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

    @Test
    public void test229JackUnassignAll() throws Exception {
        unassignAll("test229JackUnassignAll");
        assertNoDummyAccount(USER_JACK_USERNAME);
    }

    /**
     * Attribute-granting assignment that loses its validity. Resource account is granted by another (enabled) assignment.
     */
    @Test
    public void test230JackAssignRoleStrongRichSailorValidTo() throws Exception {
        final String TEST_NAME = "test230JackAssignRoleStrongRichSailorValidTo";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();

        // WHEN
        displayWhen(TEST_NAME);
        // beware of the order: weapon is weak and is set differently by role (cutlass) and resource (from user extension: pistol, mouth)
        // the assert expects cutlass, so the pirate role assignment must go first
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);
        assignRole(USER_JACK_OID, ROLE_STRONG_RICH_SAILOR_OID, activationType, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertModifyMetadata(userAfter, startTs, endTs);
        assertAssignments(userAfter, 2);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_RICH_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.ENABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID, ROLE_STRONG_RICH_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateRichSailorAccount();
    }

    /**
     * Sailor assignment expires.
     */

    @Test
    public void test232Forward15min() throws Exception {
        final String TEST_NAME = "test232Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_STRONG_RICH_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);

        assertJackDummyPirateAccount();
    }

    @Test
    public void test239JackUnassignAll() throws Exception {
        unassignAll("test239JackUnassignAll");
        assertNoDummyAccount(USER_JACK_USERNAME);
    }

    /**
     * Attribute-granting assignment that loses its validity. Resource account is granted by another (enabled) assignment.
     * Using non-strong (normal i.e. relative) mappings.
     */
    @Test
    public void test240JackAssignRoleRichSailorValidTo() throws Exception {
        final String TEST_NAME = "test240JackAssignRoleRichSailorValidTo";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activationType = new ActivationType();
        jackPirateValidTo = getTimestamp("PT10M");
        activationType.setValidTo(jackPirateValidTo);

        XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();

        // WHEN
        displayWhen(TEST_NAME);
        // beware of the order: weapon is weak and is set differently by role (cutlass) and resource (from user extension: pistol, mouth)
        // the assert expects cutlass, so the pirate role assignment must go first
        assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);
        assignRole(USER_JACK_OID, ROLE_RICH_SAILOR_OID, activationType, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertModifyMetadata(userAfter, startTs, endTs);
        assertAssignments(userAfter, 2);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_RICH_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.ENABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID, ROLE_RICH_SAILOR_OID);
        assertDelegatedRef(userAfter);

        assertJackDummyPirateRichSailorAccount();
    }

    /**
     * Sailor assignment expires.
     */

    @Test
    public void test242Forward15min() throws Exception {
        final String TEST_NAME = "test242Forward15min";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        clockForward("PT15M");

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 2);
        AssignmentType assignmentTypeAfter = assertAssignedRole(userAfter, ROLE_RICH_SAILOR_OID);
        assertEffectiveActivation(assignmentTypeAfter, ActivationStatusType.DISABLED);
        assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);

        assertJackDummyPirateAccount();
    }

    @Test
    public void test249JackUnassignAll() throws Exception {
        unassignAll("test249JackUnassignAll");
        assertNoDummyAccount(USER_JACK_USERNAME);
    }

    /**
     *  MID-4198
     */
    @Test
    public void test250JackAssignFocusExistsResource() throws Exception {
        final String TEST_NAME = "test250JackAssignFocusExistsResource";
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        ActivationType activation = new ActivationType();
        activation.setValidFrom(getTimestamp("PT10M"));
        AssignmentType assignment = ObjectTypeUtil.createAssignmentTo(resourceDummyFocusExists, prismContext).activation(activation);

        // WHEN
        displayWhen(TEST_NAME);
        ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class)
                .item(UserType.F_ASSIGNMENT).add(assignment)
                .asObjectDeltaCast(USER_JACK_OID);
        executeChanges(delta, null, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        assertLinks(userAfter, 0);

        assertNoDummyAccount(RESOURCE_DUMMY_FOCUS_EXISTS_NAME, USER_JACK_USERNAME);
    }

    /**
     * MID-4198 "Disabled assignments project value in certain cases"
     */
    @Test
    public void test252RecomputeJack() throws Exception {
        final String TEST_NAME = "test252RecomputeJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        recomputeUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        assertLinks(userAfter, 0);

        assertNoDummyAccount(RESOURCE_DUMMY_FOCUS_EXISTS_NAME, USER_JACK_USERNAME);
    }

    /**
     * MID-4198 "Disabled assignments project value in certain cases"
     */
    @Test
    public void test254ReconcileJack() throws Exception {
        final String TEST_NAME = "test254ReconcileJack";
        displayTestTitle(TEST_NAME);

        Task task =  createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        reconcileUser(USER_JACK_OID, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 1);
        assertLinks(userAfter, 0);

        assertNoDummyAccount(RESOURCE_DUMMY_FOCUS_EXISTS_NAME, USER_JACK_USERNAME);
    }

    private void assertJackDummyPirateAccount() throws Exception {
        assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, ROLE_PIRATE_TITLE);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, USER_JACK_LOCALITY);
        // Outbound mapping for weapon is weak, therefore the mapping in role should override it
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, ROLE_PIRATE_WEAPON);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, RESOURCE_DUMMY_DRINK);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
                "Jack Sparrow is the best pirate Caribbean has ever seen");
        assertNoDummyAccountAttribute(null, ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEALTH_NAME);
    }

    private void assertJackDummySailorAccount() throws Exception {
        assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, RESOURCE_DUMMY_DRINK, ROLE_SAILOR_DRINK);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, USER_JACK_LOCALITY);
    }

    private void assertJackDummyPirateSailorAccount() throws Exception {
        assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, ROLE_PIRATE_TITLE);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, RESOURCE_DUMMY_DRINK, ROLE_SAILOR_DRINK);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, USER_JACK_LOCALITY);
        // Outbound mapping for weapon is weak, therefore the mapping in role should override it
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, ROLE_PIRATE_WEAPON);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
                "Jack Sparrow is the best pirate Caribbean has ever seen");
    }

    private void assertJackDummyPirateRichSailorAccount() throws Exception {
        assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, ROLE_PIRATE_TITLE);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, RESOURCE_DUMMY_DRINK, ROLE_SAILOR_DRINK);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, USER_JACK_LOCALITY);
        // Outbound mapping for weapon is weak, therefore the mapping in role should override it
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, ROLE_PIRATE_WEAPON);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
                "Jack Sparrow is the best pirate Caribbean has ever seen");
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEALTH_NAME,
                1000000);
    }

    private void assertJackDummyPirateSingerAccount() throws Exception {
        assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, ROLE_PIRATE_TITLE, ROLE_WEAK_SINGER_TITLE);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, RESOURCE_DUMMY_DRINK);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, USER_JACK_LOCALITY);
        // Outbound mapping for weapon is weak, therefore the mapping in role should override it
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, ROLE_PIRATE_WEAPON);
        assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME,
                DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
                "Jack Sparrow is the best pirate Caribbean has ever seen");
    }

    private void unassignAll(final String TEST_NAME) throws Exception {
        displayTestTitle(TEST_NAME);

        Task task = createTask(TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
        display("User jack before", userBefore);

        // WHEN
        displayWhen(TEST_NAME);
        unassignAll(userBefore, task, result);

        // THEN
        displayThen(TEST_NAME);
        assertSuccess(result);

        PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
        display("User jack after", userAfter);
        assertAssignments(userAfter, 0);
        assertRoleMembershipRef(userAfter);

        assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    }

}


text:
#include <ctype.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

#include "ignore.h"
#include "log.h"
#include "options.h"
#include "scandir.h"
#include "util.h"

#include <fnmatch.h>
const int fnmatch_flags = FNM_PATHNAME;

/* TODO: build a huge-ass list of files we want to ignore by default (build cache stuff, pyc files, etc) */

const char *evil_hardcoded_ignore_files[] = {
    ".",
    "..",
    NULL
};

/* Warning: changing the first string will break skip_vcs_ignores. */
const char *ignore_pattern_files[] = {
    ".agignore",
    ".gitignore",
    ".git/info/exclude",
    ".hgignore",
    ".svn",
    NULL
};

const char *vcs_dirs[] = {
    ".git",
    ".svn",
    NULL
};

int is_empty(ignores *ig) {
    return (ig->extensions_len + ig->names_len + ig->slash_names_len + ig->regexes_len + ig->slash_regexes_len == 0);
};

ignores *init_ignore(ignores *parent, const char *dirname, const size_t dirname_len) {
    ignores *ig = ag_calloc(1, sizeof(ignores));

    ig->dirname = dirname;
    ig->dirname_len = dirname_len;

    if (parent && is_empty(parent) && parent->parent) {
        ig->parent = parent->parent;
    } else {
        ig->parent = parent;
    }

    if (parent && parent->abs_path_len > 0) {
        ag_asprintf(&(ig->abs_path), "%s/%s", parent->abs_path, dirname);
        ig->abs_path_len = parent->abs_path_len + 1 + dirname_len;
    } else if (dirname_len == 1 && dirname[0] == '.') {
        ig->abs_path = ag_malloc(sizeof(char));
        ig->abs_path[0] = '\0';
        ig->abs_path_len = 0;
    } else {
        ag_asprintf(&(ig->abs_path), "%s", dirname);
        ig->abs_path_len = dirname_len;
    }
    return ig;
}

void cleanup_ignore(ignores *ig) {
    if (ig == NULL) {
        return;
    }
    free_strings(ig->extensions, ig->extensions_len);
    free_strings(ig->names, ig->names_len);
    free_strings(ig->slash_names, ig->slash_names_len);
    free_strings(ig->regexes, ig->regexes_len);
    free_strings(ig->slash_regexes, ig->slash_regexes_len);
    if (ig->abs_path) {
        free(ig->abs_path);
    }
    free(ig);
}

void add_ignore_pattern(ignores *ig, const char *pattern) {
    int i;
    int pattern_len;

    /* Strip off the leading dot so that matches are more likely. */
    if (strncmp(pattern, "./", 2) == 0) {
        pattern++;
    }

    /* Kill trailing whitespace */
    for (pattern_len = strlen(pattern); pattern_len > 0; pattern_len--) {
        if (!isspace((int) pattern[pattern_len - 1])) {
            break;
        }
    }

    if (pattern_len == 0) {
        log_debug("Pattern is empty. Not adding any ignores.");
        return;
    }

    char ***patterns_p;
    size_t *patterns_len;
    size_t *patterns_size;
    if (is_fnmatch(pattern)) {
        if (pattern[0] == '*' && pattern[1] == '.' && !(is_fnmatch(pattern + 2))) {
            patterns_p = &(ig->extensions);
            patterns_len = &(ig->extensions_len);
            patterns_size = &(ig->extensions_size);
            pattern += 2;
        } else if (pattern[0] == '/') {
            patterns_p = &(ig->slash_regexes);
            patterns_len = &(ig->slash_regexes_len);
            patterns_size = &(ig->slash_regexes_size);
            pattern++;
            pattern_len--;
        } else {
            patterns_p = &(ig->regexes);
            patterns_len = &(ig->regexes_len);
            patterns_size = &(ig->regexes_size);
        }
    } else {
        if (pattern[0] == '/') {
            patterns_p = &(ig->slash_names);
            patterns_len = &(ig->slash_names_len);
            patterns_size = &(ig->slash_names_size);
            pattern++;
            pattern_len--;
        } else {
            patterns_p = &(ig->names);
            patterns_len = &(ig->names_len);
            patterns_size = &(ig->names_size);
        }
    }

    ++*patterns_len;

    /* a balanced binary tree is best for performance, but I'm lazy */
    if (*patterns_size <= *patterns_len) {
        *patterns_size = (*patterns_size) ? (*patterns_size * 2) : 16;
        *patterns_p = ag_realloc(*patterns_p,(*patterns_size) * sizeof(char *));
    }
    char **patterns = *patterns_p;

    /* TODO: de-dupe these patterns */
    for (i = *patterns_len - 1; i > 0; i--) {
        if (strcmp(pattern, patterns[i - 1]) > 0) {
            break;
        }
        patterns[i] = patterns[i - 1];
    }
    patterns[i] = ag_strndup(pattern, pattern_len);
    log_debug("added ignore pattern %s to %s", pattern, ig == root_ignores ? "root ignores" : ig->abs_path);
}

/* For loading git/hg ignore patterns */
void load_ignore_patterns(ignores *ig, const char *path) {
    FILE *fp = NULL;
    fp = fopen(path, "r");
    if (fp == NULL) {
        log_debug("Skipping ignore file %s: not readable", path);
        return;
    }
    log_debug("Loading ignore file %s.", path);

    char *line = NULL;
    ssize_t line_len = 0;
    size_t line_cap = 0;

    while ((line_len = getline(&line, &line_cap, fp)) > 0) {
        if (line_len == 0 || line[0] == '\n' || line[0] == '#') {
            continue;
        }
        if (line[line_len - 1] == '\n') {
            line[line_len - 1] = '\0'; /* kill the \n */
        }
        add_ignore_pattern(ig, line);
    }

    free(line);
    fclose(fp);
}

void load_svn_ignore_patterns(ignores *ig, const char *path) {
    FILE *fp = NULL;
    char *dir_prop_base;
    ag_asprintf(&dir_prop_base, "%s/%s", path, SVN_DIR_PROP_BASE);

    fp = fopen(dir_prop_base, "r");
    if (fp == NULL) {
        log_debug("Skipping svn ignore file %s", dir_prop_base);
        free(dir_prop_base);
        return;
    }

    char *entry = NULL;
    size_t entry_len = 0;
    char *key = ag_malloc(32); /* Sane start for max key length. */
    size_t key_len = 0;
    size_t bytes_read = 0;
    char *entry_line;
    size_t line_len;
    int matches;

    while (fscanf(fp, "K %zu\n", &key_len) == 1) {
        key = ag_realloc(key, key_len + 1);
        bytes_read = fread(key, 1, key_len, fp);
        key[key_len] = '\0';
        matches = fscanf(fp, "\nV %zu\n", &entry_len);
        if (matches != 1) {
            log_debug("Unable to parse svnignore file %s: fscanf() got %i matches, expected 1.", dir_prop_base, matches);
            goto cleanup;
        }

        if (strncmp(SVN_PROP_IGNORE, key, bytes_read) != 0) {
            log_debug("key is %s, not %s. skipping %u bytes", key, SVN_PROP_IGNORE, entry_len);
            /* Not the key we care about. fseek and repeat */
            fseek(fp, entry_len + 1, SEEK_CUR); /* +1 to account for newline. yes I know this is hacky */
            continue;
        }
        /* Aww yeah. Time to ignore stuff */
        entry = ag_malloc(entry_len + 1);
        bytes_read = fread(entry, 1, entry_len, fp);
        entry[bytes_read] = '\0';
        log_debug("entry: %s", entry);
        break;
    }
    if (entry == NULL) {
        goto cleanup;
    }
    char *patterns = entry;
    size_t patterns_len = strlen(patterns);
    while (*patterns != '\0' && patterns < (entry + bytes_read)) {
        for (line_len = 0; line_len < patterns_len; line_len++) {
            if (patterns[line_len] == '\n') {
                break;
            }
        }
        if (line_len > 0) {
            entry_line = ag_strndup(patterns, line_len);
            add_ignore_pattern(ig, entry_line);
            free(entry_line);
        }
        patterns += line_len + 1;
        patterns_len -= line_len + 1;
    }
    free(entry);
cleanup:
    free(dir_prop_base);
    free(key);
    fclose(fp);
}

static int ackmate_dir_match(const char *dir_name) {
    if (opts.ackmate_dir_filter == NULL) {
        return 0;
    }
    /* we just care about the match, not where the matches are */
    return pcre_exec(opts.ackmate_dir_filter, NULL, dir_name, strlen(dir_name), 0, 0, NULL, 0);
}

/* This is the hottest code in Ag. 10-15% of all execution time is spent here */
static int path_ignore_search(const ignores *ig, const char *path, const char *filename) {
    char *temp;
    size_t i;
    int match_pos;

BT();
    match_pos = binary_search(filename, ig->names, 0, ig->names_len);
    if (match_pos >= 0) {
        log_debug("file %s ignored because name matches static pattern %s", filename, ig->names[match_pos]);
        return 1;
    }

    if (path[0] == '/' && path[1] == '\0') {
        ag_asprintf(&temp, "/%s", filename);
    } else {
        ag_asprintf(&temp, "%s/%s", path[0] == '.' ? path + 1 : path, filename);
    }

    if (strncmp(temp, ig->abs_path, ig->abs_path_len) == 0) {
        char *slash_filename = temp + ig->abs_path_len;
        if (slash_filename[0] == '/') {
            slash_filename++;
        }
        match_pos = binary_search(slash_filename, ig->names, 0, ig->names_len);
        if (match_pos >= 0) {
            log_debug("file %s ignored because name matches static pattern %s", temp, ig->names[match_pos]);
            free(temp);
            return 1;
        }

        match_pos = binary_search(slash_filename, ig->slash_names, 0, ig->slash_names_len);
        if (match_pos >= 0) {
            log_debug("file %s ignored because name matches slash static pattern %s", slash_filename, ig->slash_names[match_pos]);
            free(temp);
            return 1;
        }

        for (i = 0; i < ig->names_len; i++) {
            char *pos = strstr(slash_filename, ig->names[i]);
            if (pos == slash_filename || (pos && *(pos - 1) == '/')) {
                pos += strlen(ig->names[i]);
                if (*pos == '\0' || *pos == '/') {
                    log_debug("file %s ignored because path somewhere matches name %s", slash_filename, ig->names[i]);
                    free(temp);
                    return 1;
                }
            }
            log_debug("pattern %s doesn't match path %s", ig->names[i], slash_filename);
        }

        for (i = 0; i < ig->slash_regexes_len; i++) {
            if (fnmatch(ig->slash_regexes[i], slash_filename, fnmatch_flags) == 0) {
                log_debug("file %s ignored because name matches slash regex pattern %s", slash_filename, ig->slash_regexes[i]);
                free(temp);
                return 1;
            }
            log_debug("pattern %s doesn't match slash file %s", ig->slash_regexes[i], slash_filename);
        }
    }

    for (i = 0; i < ig->regexes_len; i++) {
        if (fnmatch(ig->regexes[i], filename, fnmatch_flags) == 0) {
            log_debug("file %s ignored because name matches regex pattern %s", filename, ig->regexes[i]);
            free(temp);
            return 1;
        }
        log_debug("pattern %s doesn't match file %s", ig->regexes[i], filename);
    }

    int rv = ackmate_dir_match(temp);
    free(temp);
    return rv;
}

//		log_err("DAN: %s(%d)  path=%s filename=%s",__FUNCTION__, __LINE__,  path ,filename);

/* This function is REALLY HOT. It gets called for every file */
int filename_filter(const char *path, const struct dirent *dir, void *baton)
{
    const char		*filename = dir->d_name;
    size_t			filename_len, i;
    scandir_baton_t	*scandir_baton = (scandir_baton_t *)baton;
    const ignores	*ig = scandir_baton->ig;
    const char		*base_path = scandir_baton->base_path;
    const size_t	base_path_len = scandir_baton->base_path_len;
    const char		*path_start = path;
    char 			*temp;
	char			*full_path;
    struct stat 	s;
	char 			*extension = NULL;

	//skip . and ..
    for (i = 0; evil_hardcoded_ignore_files[i] != NULL; i++)
	{
        if (strcmp(filename, evil_hardcoded_ignore_files[i]) == 0)
		{
            return 0;
        }
    }

	ag_asprintf(&full_path, "%s/%s", path, filename);
    if(lstat(full_path, &s) != 0)
	{
        free(full_path);
        return 0;
    }
	free(full_path);

	if(S_ISREG(s.st_mode))
	{

	    if (!opts.search_hidden_files && filename[0] == '.')
		{
			log_debug("%s/%s ignored because it's a .xxx file", path,filename);
	        return 0;
	    }

	    if (opts.search_all_files && !opts.path_to_agignore)
		{
			log_debug("%s/%s not ignored because search_all_files enabled", path, filename);
	        return 1;
	    }

		extension = strchr(filename, '.');
		if (extension)
		{
			if (extension[1])
			{
				// The dot is not the last character, extension starts at the next one
				++extension;
			}
			else
			{
				// No extension
				extension = NULL;
			}
		}
	}
	else if(S_ISDIR(s.st_mode))
	{

		if(filename[0] == '.')
		{

			if (!opts.search_hidden_dirs)
			{
				log_debug("%s/%s ignored because it's a .xxx directory", path,filename);
	        	return 0;
	   	 	}

			if(!opts.search_vcs_dirs)
			{
		    	for(i = 0; vcs_dirs[i] != NULL; i++)
				{
    				if(strcmp(vcs_dirs[i], filename) == 0)
					{
						log_debug("%s/%s ignored because it's a VCS direcory", path,filename);
						return 0;
    				}
		    	}
			}
		}
	}
	else if(S_ISLNK(s.st_mode))
	{
		if (!opts.follow_symlinks)
		{
			log_debug("%s/%s ignored because it's a symlink", path,filename);
			return 0;
		}
	}
	else
	{
		log_debug("%s ignored because it's a not a directory or regular file or symlink", path);
	}

    /* sort of emulate basename() for base paths that begin with '/' */
    if (base_path[0] == '/') {
        for (i = 0; base_path[i] == path[i] && i < base_path_len; i++) {
            ;
        }
        if (path[i] == '/') {
            i++;
        }
        if (path[i] == '\0') {
            /*
             * base_path and path are identical...occurs when searching
             * the (top-level) contents of base_path for the first time...
             */

            path_start = base_path;
        } else {
            path_start = path + i;
        }
    }

	if(ig != NULL)
	{

    	filename_len = strlen(filename);

    	do{
	        if (strncmp(filename, "./", 2) == 0) {
	            filename++;
	            filename_len--;
	        }

	        if (extension) {
	            int match_pos = binary_search(extension, ig->extensions, 0, ig->extensions_len);
	            if (match_pos >= 0) {
	               log_debug("file %s ignored because name matches extension %s", filename, ig->extensions[match_pos]);
	                return 0;
	            }
	        }

	        if (path_ignore_search(ig, path_start, filename)) {
	           return 0;
	        }

	        if (is_directory(path, dir) && filename[filename_len - 1] != '/') {
	            ag_asprintf(&temp, "%s/", filename);
	            int rv = path_ignore_search(ig, path_start, temp);
	            free(temp);
	            if (rv) {
	               return 0;
	            }
	        }

	        ig = ig->parent;

	    }while (ig != NULL);
	}

    log_debug("%s/%s not ignored",  path, filename);

    return 1;
}

redpajama_set_name: RedPajamaGithub


text:
BOARD_TAG    = uno
ARDUINO_PORT = /dev/ttyACM3

ARDUINO_DIR   = /usr/share/arduino
ARDMK_DIR     = /usr
AVR_TOOLS_DIR = /usr

ARDUINO_LIBS = SPI Ethernet Ethernet/utility SD TinyWebServer EthernetDHCP EthernetDHCP/utility Flash
#ARDUINO_USER_LIBS = TinyWebServer EthernetDHCP Flash
#USER_LIBS     = $(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_USER_LIBS))

CFLAGS += -Wno-deprecated-declarations -D__PROG_TYPES_COMPAT__

include /usr/share/arduino/Arduino.mk


text:
package frame

import (
	"bufio"
	"io"
)

// TODO: Improve Error Handling
type Writer struct {
	writer *bufio.Writer
}

func NewWriter(w io.Writer) *Writer {
	return &Writer{
		writer: bufio.NewWriterSize(w, writeBufSize),
	}
}

func (writer *Writer) Write(frame *Frame) (err error) {
	if frame == nil {
		// heart-beat
		_, err = writer.writer.Write(BytesLF)
		if err != nil {
			return err
		}
	} else {
		// Command:
		_, err = writer.writer.Write([]byte(frame.Command))
		if err != nil {
			return err
		}
		_, err = writer.writer.Write(BytesLF)
		if err != nil {
			return err
		}
		// Headers:
		if frame.Headers != nil {
			for key, value := range frame.Headers {
				_, err = writer.writer.Write([]byte(key))
				if err != nil {
					return err
				}
				_, err = writer.writer.Write(BytesColon)
				if err != nil {
					return err
				}
				_, err = writer.writer.Write([]byte(value))
				if err != nil {
					return err
				}
				_, err = writer.writer.Write(BytesLF)
				if err != nil {
					return err
				}
			}
		}
		_, err = writer.writer.Write(BytesLF)
		if err != nil {
			return err
		}
		// Body:
		if len(frame.Body) > 0 {
			_, err = writer.writer.Write([]byte(frame.Body))
			if err != nil {
				return err
			}
		}
		// End:
		_, err = writer.writer.Write(BytesNull)
		if err != nil {
			return err
		}
	}
	err = writer.writer.Flush()
	if err != nil {
		return err
	}
	return nil
}


text:
var scoutApp = angular.module('scoutApp', ["firebase"]);
var scout;

//var fb = new Firebase("https://blazing-heat-189.firebaseio.com/scout/");
//fb.on("value", function(data) {
//  scout = data.val();
//  alert(scout.firstName);
//
//});

scoutApp.controller('ScoutCtrl', ["$scope", "$firebase",
  function ($scope, $firebase) {
    var scoutFb = new Firebase("https://blazing-heat-189.firebaseio.com/scouts/0/");
    var awardsFb = new Firebase("https://blazing-heat-189.firebaseio.com/awards/");

    var scoutSync = $firebase(scoutFb);
    var awards = $firebase(awardsFb).$asObject;

    $scope.scout = scoutSync.$asObject();

    // This function is not currently working - why?
    $scope.scout.currentRank = function() {
      function getAwardReqs(awardId) {
        awards.forEach(function(current) {
          if (current.awardId === awardId) {
            return current.reqId;
          }
        });
      }

      function isComplete(award) {
        var awardId = award.awardId;
        var awardReqs = getAwardReqs(awardId);
        var competedReqs = getCompletedReqs(awardId);

        for (var i = 0; i < awardReqs.length; i++) {
           if (competedReqs.indexOf(awardReqs[i]) === -1) {
             return false;
           }
        }
        return true;
      }

      var awardsStarted = this.requirementsCompleted.map(function(current) {
        var getAwardObj = function(awardId) {
          for (var i = 0; i < awards.length; i++) {
            if (awards[i].awardId === awardId) {
              return awards[i];
            }
          }
        }

        var award = getAwardObj(current.awardId);
        alert(award.awardName);
        return award;
      });

      var awardsCompleted = awardsStarted.forEach(function(current) {
        if(isComplete(current)) {
          return current;
        }
      });

      //This would work much better if the award data were structured as an array of requirements
      // right now we will just return the first one in the array. we need to define an order somehow
      return awardsCompleted[0];
    }
  }
]);


text:
var ss_IEnumerator = function#? DEBUG IEnumerator$##() { };

ss_IEnumerator.__typeName = 'ss.IEnumerator';
ss.IEnumerator = ss_IEnumerator;
ss.initInterface(ss_IEnumerator, { current: null, moveNext: null, reset: null }, [ss_IDisposable]);


text:
hrm
===========

[![Build Status](https://travis-ci.org/hschink/hrm-manager.svg)](https://travis-ci.org/hschink/hrm-manager)

An Hibernate test project for experiments

## Tests ##

Run tests on the command-line with ``gradle test`` or use Eclipse's built-in JUnit runner.

## Development ##

If you like to join hrm development you may just want to use [Eclipse IDE][eclipse].
Just use [gradle's Eclipse plug-in][eclipse plug-in] with ``gradle eclipse`` to create the necessary Eclipse
configuration files.

Happy programming! :smile:

[eclipse]: [http://www.eclipse.org/]
[eclipse plug-in]: [http://www.gradle.org/docs/current/userguide/eclipse_plugin.html]


text:
![build status](https://travis-ci.org/NullSoldier/gulp-indexpipe.svg)

**This readme is still under construction and is not gauranteed to be correct**

This task is designed for gulp 3. Was based off of https://github.com/pursual/gulp-usemin

gulp-indexpipe reads sections from an index file, does processing in gulp, and writes the file references back into the block after you are finished.

This lets you do many things that gulp-usemin will not allow you to do such as separate your debug and release build processes in gulp in a very clean way.

Consider the example usage example below...

## Usage Example

This is a standard looking index file. You have some vendor dependencies, scripts, and styles. When you make a debug build, the file references that should be listed will be very different than when you perform a release build. Let's see how that works below...

```html
<head>
  <!-- build:css styles-->
  <link rel="stylesheet" type="text/css" href="style/home.css">
  <link rel="stylesheet" type="text/css" href="style/about.css">
  <!-- endbuild -->
</head>

<body>
  <!-- build:js vendor-->
  <script src="vendor/angular.min.js"></script>
  <script src="vendor/bootstrap.min.js"></script>
  <!-- endbuild -->

  <!-- build:js scripts -->
  <script src="src/app.js"></script>
  <script src="src/utils.js"></script>
  <!-- endbuild -->
</body>
```

Now here is what your build process might look like using gulp-indexpipe. in gulp. Note that there is no concatenation or minifaction going on. It's building source maps and simply copying files to your output directory for fastest iteration time.

When you use gulp.dest in gulp-indexpipe., gulp-indexpipe. will take the resulting references and copy them back into the index file where they came from. In the case of a debug build, this is an identity operation.

```javascript
gulp.task('build-debug', function() {

  gulp.src('index.html')
    buildScripts = sourcemaps.init()
      .pipe(coffee())
      .pipe(sourcemaps.write())
      .pipe(gulp.dest('build'))

    buildVendor = gulp.dest('build')
    buildStyles = gulp.dest('build')

    indexpipe({
      scripts: buildScripts,
      vendor : buildVendor,
      styles : buildStyles
    })).pipe(gulp.dest('build/'));
});
```

This is what your release build might look like. Note that minification and concatenation is happening which reduces the file references in the stream to a single file. Once gulp-indexpipe. sees the single file from each build process, it copies that into the block from which the file references came from.

Look below to see what the resulting index.html file will look like as output from gulp-indexpipe.

```javascript
gulp.task('build-release', function() {

  gulp.src('index.html')
    buildScripts = coffee()
      .pipe(ngAnnotate())
      .pipe(uglify())
      .pipe(concat('scripts.js')
      .pipe(gulp.dest('build'))

    buildVendor = concat('vendor.js')
      .pipe(gulp.dest 'build')

    buildStyles = minifyCss()
      .pipe(concat('styles.css')
      .pipe(gulp.dest('build')

    indexpipe({
      scripts: buildScripts,
      vendor : buildVendor,
      styles : buildStyles
    })).pipe(gulp.dest('build/'));
});
```

```html
<head>
  <link rel="stylesheet" type="text/css" href="styles.css">
</head>

<body>
  <script src="vendor.js"></script>
  <script src="scripts.js"></script>
</body>
```
## API

### Blocks
Blocks are expressed as:

```html
<!-- build:<type>(alternate search path) <name> -->
... HTML Markup, list of script / link tags.
<!-- endbuild -->
```

- **type**: either `js` or `css`
- **alternate search path**: (optional) By default the input files are relative to the treated file. Alternate search path allows one to change that
- **name**: the name of the section to be references in your gulpfile


text:
package org.apache.wicket.osgi;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.apache.wicket.util.string.Strings;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
 * A test that verifies that there are no non-empty packages with the same name in two or more
 * wicket modules.
 *
 * Based on https://gist.github.com/1977817, contributed by Andreas Pieber
 */
class OsgiClashingPackagesTest
{

	@Test
	void collectProjectPackages() throws IOException
	{
		char pathSeparator = System.getProperty("path.separator").charAt(0);
		String classpath = System.getProperty("java.class.path");
		String[] dependencies = Strings.split(classpath, pathSeparator);

		// packageName -> projects containing a package with this name
		Map<String, List<Project>> projectBuckets = new HashMap<>();

		for (String dependency : dependencies)
		{
			// process only wicket-xyz.jar
			if (dependency.contains("wicket-") && dependency.endsWith(".jar"))
			{
				JarFile jarFile = new JarFile(dependency);
				try
				{
					String projectName = Strings.afterLast(dependency, '/');
					Project project = new Project(projectName, jarFile);
					project.addTo(projectBuckets);
				}
				finally
				{
					jarFile.close();
				}
			}
		}

		Set<Entry<String, List<Project>>> entrySet = projectBuckets.entrySet();
		for (Entry<String, List<Project>> entry : entrySet)
		{
			List<Project> projects = entry.getValue();
			if (projects.size() > 1)
			{
				fail(entry);
			}
		}
	}

	private void fail(Entry<String, List<Project>> entry)
	{
		StringBuilder builder = new StringBuilder();
		String packageName = entry.getKey();
		builder.append("Package '").append(packageName).append(
			"' has files in two or more modules: ");
		for (Project conflict : entry.getValue())
		{
			builder.append(conflict.getName()).append(", ");
		}
		try
		{
			builder.append("\nResources:\n");
			Enumeration<URL> resources = getClass().getClassLoader().getResources(packageName);
			while (resources.hasMoreElements())
			{
				URL resource = resources.nextElement();
				builder.append("\n\t").append(resource.toExternalForm());
			}
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		Assertions.fail(builder.toString());
	}

	private static class Project
	{
		// a set with all package names in a dependency
		private final Set<String> packagesWithContent = new TreeSet<>();

		// the name of the dependency
		private final String name;

		public Project(String name, JarFile jarFile)
		{
			this.name = name;
			collectPackageNames(jarFile);
		}

		/**
		 * Adds this project to as a value in the global map that contains 'packageName ->
		 * List[Project]'
		 *
		 * @param projectBuckets
		 *            the global map
		 */
		public void addTo(Map<String, List<Project>> projectBuckets)
		{
			for (String packageWithContent : packagesWithContent)
			{
				if (!"".equals(packageWithContent))
				{
					if (!projectBuckets.containsKey(packageWithContent))
					{
						projectBuckets.put(packageWithContent, new ArrayList<>());
					}
					projectBuckets.get(packageWithContent).add(this);
				}
			}
		}

		/**
		 * Collects the names of all packages in this JarFile
		 *
		 * @param jarFile
		 *            the jar file to analyze
		 */
		private void collectPackageNames(final JarFile jarFile)
		{
			Enumeration<JarEntry> entries = jarFile.entries();
			while (entries.hasMoreElements())
			{
				JarEntry jarEntry = entries.nextElement();
				String entryName = jarEntry.getName();
				if (shouldCollect(entryName))
				{
					String packageName = Strings.beforeLast(entryName, '/');
					packagesWithContent.add(packageName);
				}
			}
		}

		public String getName()
		{
			return name;
		}

		@Override
		public String toString()
		{
			return "Project{" + "name='" + name + '\'' + '}';
		}

		private boolean shouldCollect(final String entryName)
		{
            return !entryName.endsWith("/") &&

                    // all modules have META-INF {MANIFEST.MF, Maven stuff, ..}
                    !entryName.startsWith("META-INF/") &&

                    // ignore Wicket's IInitializer conf files
                    (!entryName.startsWith("META-INF/wicket") || !entryName.endsWith(".properties"));
        }
	}

}


text:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="test-to-html.xml" type="text/xml"?>

<!--

Copyright (c) 2001 World Wide Web Consortium,
(Massachusetts Institute of Technology, Institut National de
Recherche en Informatique et en Automatique, Keio University).  All
Rights Reserved.  This program is distributed under the W3C's Software
Intellectual Property License.  This program is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

See W3C License http://www.w3.org/Consortium/Legal/ for more details.

-->
<!DOCTYPE test SYSTEM "dom1.dtd">
<test xmlns="http://www.w3.org/2001/DOM-Test-Suite/Level-1" name="HTMLTableElement27">
<metadata>
<title>HTMLTableElement27</title>
<creator>NIST</creator>
<description>
    The deleteCaption() method deletes the table caption.

    Delete the CAPTION element on the second TABLE element.
</description>
<contributor>Rick Rivello</contributor>
<date qualifier="created">2002-05-02</date>
<subject resource="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html#ID-22930071"/>
</metadata>
<var name="nodeList" type="NodeList"/>
<var name="testNode" type="Node"/>
<var name="vsection1" type="HTMLTableSectionElement" />
<var name="vsection2" type="HTMLTableSectionElement" />
<var name="valign" type="DOMString"/>
<var name="doc" type="Document"/>
<load var="doc" href="table" willBeModified="true"/>
<getElementsByTagName interface="Document" obj="doc" var="nodeList" tagname='"table"'/>
<assertSize collection="nodeList" size="3" id="Asize"/>
<item interface="NodeList" obj="nodeList" var="testNode" index="1"/>
<caption interface="HTMLTableElement" obj="testNode" var="vsection1"/>
<assertNotNull actual="vsection1" id="vsection1Id"/>
<deleteCaption interface="HTMLTableElement" obj="testNode"/>
<caption interface="HTMLTableElement" obj="testNode" var="vsection2"/>
<assertNull actual="vsection2" id="vsection2Id"/>
</test>