Search in sources :

Example 1 with PartyRole

use of org.estatio.module.party.dom.role.PartyRole in project estatio by estatio.

the class Party_Test method validate_delete_works.

@Test
public void validate_delete_works() throws Exception {
    // given
    PartyRoleType typeForTenant = new PartyRoleType();
    PartyRole roleForTenant = new PartyRole();
    roleForTenant.setRoleType(typeForTenant);
    Party partyToDelete = new PartyForTesting();
    // party to delete now has tenant role
    partyToDelete.getRoles().add(roleForTenant);
    partyToDelete.partyRoleTypeRepository = mockPartyRoleTypeRepository;
    PartyRoleType typeForSupplier = new PartyRoleType();
    PartyRole roleForSupplier = new PartyRole();
    roleForSupplier.setRoleType(typeForSupplier);
    Party replacementParty = new PartyForTesting();
    // replacement party now has supplier role but NOT tenant role
    replacementParty.getRoles().add(roleForSupplier);
    replacementParty.partyRoleTypeRepository = mockPartyRoleTypeRepository;
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockPartyRoleTypeRepository).findByKey("TENANT");
            will(returnValue(typeForTenant));
            oneOf(mockPartyRoleTypeRepository).findByKey("SUPPLIER");
            will(returnValue(typeForSupplier));
            oneOf(mockPartyRoleTypeRepository).findByKey("TENANT");
            will(returnValue(null));
        }
    });
    // when, then
    Assertions.assertThat(partyToDelete.validateDelete(replacementParty)).isEqualTo("A tenant should not be replaced by a supplier");
}
Also used : Expectations(org.jmock.Expectations) PartyRole(org.estatio.module.party.dom.role.PartyRole) PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) AbstractBeanPropertiesTest(org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest) Test(org.junit.Test)

Example 2 with PartyRole

use of org.estatio.module.party.dom.role.PartyRole in project estatio by estatio.

the class PersonPartyRolesBuilder method execute.

@Override
public void execute(ExecutionContext executionContext) {
    checkParam("person", executionContext, Person.class);
    for (IPartyRoleType partyRoleType : partyRoleTypes) {
        final PartyRole partyRole = partyRoleTypeService.createRole(person, partyRoleType);
        object.add(partyRole);
    }
}
Also used : PartyRole(org.estatio.module.party.dom.role.PartyRole) IPartyRoleType(org.estatio.module.party.dom.role.IPartyRoleType)

Example 3 with PartyRole

use of org.estatio.module.party.dom.role.PartyRole in project estatio by estatio.

the class IncomingInvoiceApprovalState_IntegTest method complete_should_fail_when_not_having_appropriate_role_type_test.

@Test
public void complete_should_fail_when_not_having_appropriate_role_type_test() {
    Exception error = new Exception();
    // given
    Person personEmmaWithNoRoleAsPropertyManager = (Person) partyRepository.findPartyByReference(Person_enum.EmmaTreasurerGb.getRef());
    SortedSet<PartyRole> rolesforEmma = personEmmaWithNoRoleAsPropertyManager.getRoles();
    assertThat(rolesforEmma.size()).isEqualTo(1);
    assertThat(rolesforEmma.first().getRoleType()).isEqualTo(partyRoleTypeRepository.findByKey(PartyRoleTypeEnum.TREASURER.getKey()));
    // when
    try {
        // workaround: clear MeService#me cache
        queryResultsCache.resetForNextTransaction();
        sudoService.sudo(Person_enum.EmmaTreasurerGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_complete.class, incomingInvoice)).act("PROPERTY_MANAGER", null, null));
    } catch (DisabledException e) {
        error = e;
    }
    assertThat(error.getMessage()).isNotNull();
    assertThat(error.getMessage()).contains("Reason: Task assigned to 'PROPERTY_MANAGER' role");
}
Also used : PartyRole(org.estatio.module.party.dom.role.PartyRole) DisabledException(org.apache.isis.applib.services.wrapper.DisabledException) Person(org.estatio.module.party.dom.Person) DisabledException(org.apache.isis.applib.services.wrapper.DisabledException) Test(org.junit.Test)

Example 4 with PartyRole

use of org.estatio.module.party.dom.role.PartyRole in project estatio by estatio.

the class IncomingInvoiceApprovalState_IntegTest method complete_works_when_having_appropriate_role_type_test.

@Test
public void complete_works_when_having_appropriate_role_type_test() {
    Exception error = new Exception();
    // given
    Person personEmma = (Person) partyRepository.findPartyByReference(Person_enum.EmmaTreasurerGb.getRef());
    PartyRoleType roleAsPropertyManager = partyRoleTypeRepository.findByKey("PROPERTY_MANAGER");
    personEmma.addRole(roleAsPropertyManager);
    transactionService.nextTransaction();
    SortedSet<PartyRole> rolesforEmma = personEmma.getRoles();
    assertThat(rolesforEmma.size()).isEqualTo(2);
    assertThat(rolesforEmma.first().getRoleType()).isEqualTo(partyRoleTypeRepository.findByKey("PROPERTY_MANAGER"));
    // when
    try {
        // workaround: clear MeService#me cache
        queryResultsCache.resetForNextTransaction();
        sudoService.sudo(Person_enum.EmmaTreasurerGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_complete.class, incomingInvoice)).act("PROPERTY_MANAGER", null, null));
    } catch (DisabledException e) {
        error = e;
    }
    assertThat(error.getMessage()).isNull();
    assertThat(incomingInvoice.getApprovalState()).isEqualTo(IncomingInvoiceApprovalState.COMPLETED);
}
Also used : PartyRole(org.estatio.module.party.dom.role.PartyRole) DisabledException(org.apache.isis.applib.services.wrapper.DisabledException) PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) Person(org.estatio.module.party.dom.Person) DisabledException(org.apache.isis.applib.services.wrapper.DisabledException) Test(org.junit.Test)

Example 5 with PartyRole

use of org.estatio.module.party.dom.role.PartyRole in project estatio by estatio.

the class EnforceTaskAssignmentPolicySubscriber_applyPolicy_Test method setUp.

@Before
public void setUp() throws Exception {
    subscriber = new EnforceTaskAssignmentPolicySubscriber();
    subscriber.stateTransitionService = mockStateTransitionService;
    subscriber.personRepository = mockPersonRepository;
    subscriber.metaModelService3 = mockMetaModelService3;
    domainObject = new BankAccount();
    stateTransitionClass = BankAccountVerificationStateTransition.class;
    pendingTransition = new BankAccountVerificationStateTransition();
    personTaskAssignedTo = new Person();
    personTaskAssignedTo.setReference("JBLOGGS");
    roleTaskAssignedTo = new PartyRoleType();
    roleTaskAssignedTo.setKey("Treasurer");
    pendingTask = new Task(roleTaskAssignedTo, personTaskAssignedTo, "some description", LocalDateTime.now(), // objectType of transition class
    "bankAccount.BankAccountVerificationStateTransition");
    pendingTransition.setTask(pendingTask);
    personForMe = new Person();
    personForMe.getRoles().add(new PartyRole(personForMe, roleTaskAssignedTo));
    assertThat(pendingTransition.getTask()).isNotNull();
    assertThat(personForMe.getRoles()).isNotEmpty();
    assertThat(Lists.newArrayList(personForMe.getRoles()).stream().map(PartyRole::getRoleType)).contains(roleTaskAssignedTo);
}
Also used : PartyRole(org.estatio.module.party.dom.role.PartyRole) Task(org.estatio.module.capex.dom.task.Task) PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) BankAccount(org.estatio.module.financial.dom.BankAccount) Person(org.estatio.module.party.dom.Person) BankAccountVerificationStateTransition(org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition) Before(org.junit.Before)

Aggregations

PartyRole (org.estatio.module.party.dom.role.PartyRole)5 Person (org.estatio.module.party.dom.Person)3 PartyRoleType (org.estatio.module.party.dom.role.PartyRoleType)3 Test (org.junit.Test)3 DisabledException (org.apache.isis.applib.services.wrapper.DisabledException)2 BankAccountVerificationStateTransition (org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)1 Task (org.estatio.module.capex.dom.task.Task)1 BankAccount (org.estatio.module.financial.dom.BankAccount)1 IPartyRoleType (org.estatio.module.party.dom.role.IPartyRoleType)1 AbstractBeanPropertiesTest (org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest)1 Expectations (org.jmock.Expectations)1 Before (org.junit.Before)1