Search in sources :

Example 16 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class GroupActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    userContext = TestObjectFactory.getContext();
    request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("recordOfficeId", "1");
    request.getSession(false).setAttribute("ActivityContext", TestObjectFactory.getActivityContext());
    flowKey = createFlow(request, GroupCustAction.class);
    EntityMasterData.getInstance().init();
    FieldConfig fieldConfig = FieldConfig.getInstance();
    fieldConfig.init();
    getActionServlet().getServletContext().setAttribute(Constants.FIELD_CONFIGURATION, fieldConfig.getEntityMandatoryFieldMap());
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) FieldConfig(org.mifos.framework.components.fieldConfiguration.util.helpers.FieldConfig) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Example 17 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class ClientCustActionStrutsTest method testCreateSuccessWithoutGroup.

@Test
public void testCreateSuccessWithoutGroup() throws Exception {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    //        List<FeeDto> feesToRemove = getFees(RecurrenceType.WEEKLY);
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "load");
    addRequestParameter("officeId", "3");
    addRequestParameter("groupFlag", "0");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    flowKey = (String) request.getAttribute(Constants.CURRENTFLOWKEY);
    List<BusinessActivityEntity> povertyStatus = (List<BusinessActivityEntity>) SessionUtils.getAttribute(ClientConstants.POVERTY_STATUS, request);
    List<CustomFieldDto> customFieldDefs = getCustomFieldFromSession();
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "next");
    addRequestParameter("officeId", "3");
    addRequestParameter("clientName.salutation", "1");
    addRequestParameter("clientName.firstName", "Client");
    addRequestParameter("clientName.lastName", "LastName");
    addRequestParameter("spouseName.firstName", "Spouse");
    addRequestParameter("spouseName.lastName", "LastName");
    addRequestParameter("spouseName.nameType", "1");
    addRequestDateParameter("dateOfBirth", "20/3/1987");
    addRequestParameter("clientDetailView.gender", "1");
    addRequestParameter("input", "personalInfo");
    addRequestParameter("customerDetail.povertyStatus", povertyStatus.get(0).getId().toString());
    int i = 0;
    for (CustomFieldDto customFieldDef : customFieldDefs) {
        addRequestParameter("customField[" + i + "].fieldId", customFieldDef.getFieldId().toString());
        addRequestParameter("customField[" + i + "].fieldValue", "Req");
        i++;
    }
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    MeetingBO weeklyMeeting = new MeetingBuilder().weekly().every(1).occuringOnA(WeekDay.WEDNESDAY).build();
    SessionUtils.setAttribute(CustomerConstants.CUSTOMER_MEETING, weeklyMeeting, request);
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "preview");
    addRequestParameter("input", "mfiInfo");
    addRequestParameter("loanOfficerId", "1");
    addRequestParameter("formedByPersonnel", "1");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.preview_success.toString());
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "create");
    addRequestParameter("input", "create");
    addRequestParameter("status", "1");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.create_success.toString());
    ClientCustActionForm actionForm = (ClientCustActionForm) request.getSession().getAttribute("clientCustActionForm");
    client = TestObjectFactory.getClient(actionForm.getCustomerIdAsInt());
//        removeFees(feesToRemove);
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) BusinessActivityEntity(org.mifos.application.master.business.BusinessActivityEntity) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) List(java.util.List) ArrayList(java.util.ArrayList) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) Test(org.junit.Test)

Example 18 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class TestSaveCollectionSheetUtils method createSampleCenterHierarchy.

/**
     * By default generates 1 center, 1 group and 1 client with 1 loan to be disbursed and 1
     * weekly account collection fee. Can be configured to add in other invalid entries.
     */
public void createSampleCenterHierarchy(Date date) throws Exception {
    MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).startingToday().build();
    IntegrationTestObjectMother.saveMeeting(weeklyMeeting);
    center = new CenterBuilder().withNumberOfExistingCustomersInOffice(3).with(weeklyMeeting).withName("Center").with(sampleBranchOffice()).withLoanOfficer(testUser()).build();
    IntegrationTestObjectMother.createCenter(center, weeklyMeeting);
    group = new GroupBuilder().withMeeting(weeklyMeeting).withName("Group").withOffice(sampleBranchOffice()).withLoanOfficer(testUser()).withParentCustomer(center).build();
    IntegrationTestObjectMother.createGroup(group, weeklyMeeting);
    AmountFeeBO weeklyPeriodicFeeForFirstClients = new FeeBuilder().appliesToClientsOnly().withFeeAmount("87.0").withName("First Client Weekly Periodic Fee").withSameRecurrenceAs(weeklyMeeting).with(sampleBranchOffice()).build();
    IntegrationTestObjectMother.saveFee(weeklyPeriodicFeeForFirstClients);
    client = new ClientBuilder().withMeeting(weeklyMeeting).withName("Client 1").withOffice(sampleBranchOffice()).withLoanOfficer(testUser()).withParentCustomer(group).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(client, weeklyMeeting);
    MeetingBO loanMeeting = TestObjectFactory.createLoanMeeting(client.getCustomerMeeting().getMeeting());
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", ApplicableTo.CLIENTS, date, PrdStatus.LOAN_ACTIVE, 1200.0, 1.2, 12, InterestType.FLAT, loanMeeting);
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    BigDecimal loanAmount = BigDecimal.valueOf(Double.valueOf("1200.0"));
    BigDecimal minAllowedLoanAmount = loanAmount;
    BigDecimal maxAllowedLoanAmount = loanAmount;
    Double interestRate = Double.valueOf("10.0");
    LocalDate disbursementDate = new LocalDate(date);
    int numberOfInstallments = 12;
    int minAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
    int maxAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
    int graceDuration = 0;
    Integer sourceOfFundId = null;
    Integer loanPurposeId = null;
    Integer collateralTypeId = null;
    String collateralNotes = null;
    String externalId = null;
    boolean repaymentScheduleIndependentOfCustomerMeeting = false;
    RecurringSchedule recurringSchedule = null;
    List<CreateAccountFeeDto> accountFees = new ArrayList<CreateAccountFeeDto>();
    CreateLoanAccount createLoanAccount = new CreateLoanAccount(client.getCustomerId(), loanOffering.getPrdOfferingId().intValue(), AccountState.LOAN_APPROVED.getValue().intValue(), loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, interestRate, disbursementDate, null, numberOfInstallments, minAllowedNumberOfInstallments, maxAllowedNumberOfInstallments, graceDuration, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId, repaymentScheduleIndependentOfCustomerMeeting, recurringSchedule, accountFees, new ArrayList<CreateAccountPenaltyDto>());
    loan = IntegrationTestObjectMother.createClientLoan(createLoanAccount);
    loan.updateDetails(TestUtils.makeUser());
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) MeetingBO(org.mifos.application.meeting.business.MeetingBO) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ArrayList(java.util.ArrayList) CenterBuilder(org.mifos.domain.builders.CenterBuilder) LocalDate(org.joda.time.LocalDate) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) ClientBuilder(org.mifos.domain.builders.ClientBuilder) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) BigDecimal(java.math.BigDecimal) FeeBuilder(org.mifos.domain.builders.FeeBuilder) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) Authentication(org.springframework.security.core.Authentication) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) SecurityContext(org.springframework.security.core.context.SecurityContext) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder)

Example 19 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class SavingsServiceFacadeWebTierTest method setupAndInjectDependencies.

@Before
public void setupAndInjectDependencies() {
    oldCurrency = Money.getDefaultCurrency();
    Money.setDefaultCurrency(TestUtils.RUPEE);
    savingsServiceFacade = new SavingsServiceFacadeWebTier(savingsDao, savingsProductDao, personnelDao, customerDao, holidayDao);
    ((SavingsServiceFacadeWebTier) savingsServiceFacade).setSavingsInterestScheduledEventFactory(savingsInterestScheduledEventFactory);
    ((SavingsServiceFacadeWebTier) savingsServiceFacade).setTransactionHelper(transactionHelper);
    MifosUser principal = new MifosUserBuilder().build();
    SecurityContext securityContext = SecurityContextHolder.getContext();
    if (securityContext == null) {
        securityContext = new SecurityContextImpl();
        SecurityContextHolder.setContext(securityContext);
    }
    if (securityContext.getAuthentication() == null || !securityContext.getAuthentication().isAuthenticated()) {
        Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal, principal.getAuthorities());
        securityContext.setAuthentication(authentication);
    }
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) Before(org.junit.Before)

Example 20 with MifosUserBuilder

use of org.mifos.builders.MifosUserBuilder in project head by mifos.

the class EditCustomerStatusActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    UserContext userContext = TestObjectFactory.getContext();
    request.getSession().setAttribute(Constants.USER_CONTEXT_KEY, userContext);
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("recordOfficeId", "1");
    request.getSession(false).setAttribute("ActivityContext", TestObjectFactory.getActivityContext());
    flowKey = createFlow(request, EditCustomerStatusAction.class);
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) UserContext(org.mifos.security.util.UserContext) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Aggregations

MifosUserBuilder (org.mifos.builders.MifosUserBuilder)29 MifosUser (org.mifos.security.MifosUser)29 Authentication (org.springframework.security.core.Authentication)29 SecurityContext (org.springframework.security.core.context.SecurityContext)29 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)29 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)28 Before (org.junit.Before)13 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)5 MeetingBO (org.mifos.application.meeting.business.MeetingBO)5 Money (org.mifos.framework.util.helpers.Money)4 BigDecimal (java.math.BigDecimal)3 Date (java.util.Date)3 Locale (java.util.Locale)3 LocalDate (org.joda.time.LocalDate)3 BeforeClass (org.junit.BeforeClass)3 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)3 RecurringSchedule (org.mifos.clientportfolio.loan.service.RecurringSchedule)3 CreateLoanAccount (org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount)3 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)3