<commit_before>/*
 * Copyright Grameen Foundation USA
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * See also http://www.apache.org/licenses/LICENSE-2.0.html for an
 * explanation of the license and how it is applied.
 */

package org.mifos.test.acceptance.admin;


import org.joda.time.DateTime;
import org.mifos.framework.util.DbUnitUtilities;
import org.mifos.test.acceptance.framework.MifosPage;
import org.mifos.test.acceptance.framework.UiTestCaseBase;
import org.mifos.test.acceptance.framework.admin.AdminPage;
import org.mifos.test.acceptance.framework.admin.ManageRolePage;
import org.mifos.test.acceptance.framework.admin.ViewRolesPage;
import org.mifos.test.acceptance.framework.loan.LoanAccountPage;
import org.mifos.test.acceptance.framework.loanproduct.DefineNewLoanProductPage;
import org.mifos.test.acceptance.framework.office.OfficeParameters;
import org.mifos.test.acceptance.framework.testhelpers.LoanTestHelper;
import org.mifos.test.acceptance.framework.testhelpers.NavigationHelper;
import org.mifos.test.acceptance.loanproduct.LoanProductTestHelper;
import org.mifos.test.acceptance.remote.InitializeApplicationRemoteTestingService;
import org.mifos.test.acceptance.util.ApplicationDatabaseOperation;
import org.mifos.test.acceptance.util.TestDataSetup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

@ContextConfiguration(locations = { "classpath:ui-test-context.xml" })
@Test(sequential = true, groups = {"admin", "acceptance","ui"})
public class RolesAndPermissionTest extends UiTestCaseBase {

    private NavigationHelper navigationHelper;

    @Autowired
    private DriverManagerDataSource dataSource;
    @Autowired
    private DbUnitUtilities dbUnitUtilities;
    @Autowired
    private InitializeApplicationRemoteTestingService initRemote;
    private LoanTestHelper loanTestHelper;
    private LoanProductTestHelper loanProductTestHelper;
    private DateTime systemDateTime;
    @Autowired
    private ApplicationDatabaseOperation applicationDatabaseOperation;
    private final static String userLoginName = "test_user";
    private final static String officeName = "test_office";
    private final static String clientName = "test client";
    private final static String userName="test user";

    @Override
    @SuppressWarnings("PMD.SignatureDeclareThrowsException")    // one of the dependent methods throws Exception
    @BeforeMethod
    public void setUp() throws Exception {
        super.setUp();
        navigationHelper = new NavigationHelper(selenium);
        loanTestHelper = new LoanTestHelper(selenium);
        loanProductTestHelper = new LoanProductTestHelper(selenium);
        systemDateTime = new DateTime(2010, 10, 11, 10, 0, 0, 0);
        TestDataSetup dataSetup = new TestDataSetup(selenium, applicationDatabaseOperation);
        loanTestHelper.setApplicationTime(systemDateTime);
        dataSetup.createBranch(OfficeParameters.BRANCH_OFFICE, officeName, "Off");
        dataSetup.createUser(userLoginName, userName, officeName);
        dataSetup.createClient(clientName, officeName, userName);
        dataSetup.addDecliningPrincipalBalance();
    }


    @AfterMethod
    public void tearDown() {
        (new MifosPage(selenium)).logout();
    }

    @SuppressWarnings("PMD.SignatureDeclareThrowsException")
    public void adjustmentOfPostDatedTransactions() throws Exception {
        navigationHelper.navigateToAdminPage().navigateToViewRolesPage().navigateToManageRolePage("Admin").disablePermission("5_1_9").
                verifyPermissionText("5_1_9", "Can adjust back dated transactions").submitAndGotoViewRolesPage();
        DefineNewLoanProductPage.SubmitFormParameters formParameters = loanProductTestHelper.defineLoanProductParameters(5,1000,20,DefineNewLoanProductPage.SubmitFormParameters.DECLINING_BALANCE_INTEREST_RECALCULATION);
        loanProductTestHelper.
                navigateToDefineNewLoanPangAndFillMandatoryFields(formParameters).
                submitAndGotoNewLoanProductPreviewPage().submit();
        loanTestHelper.createLoanAccount(clientName, formParameters.getOfferingName());
        loanTestHelper.approveLoan();
        loanTestHelper.disburseLoan(systemDateTime.plusDays(1));
        loanTestHelper.makePayment(systemDateTime.plusDays(10),"10");
        loanTestHelper.setApplicationTime(systemDateTime.plusDays(11)).navigateBack();
        new LoanAccountPage(selenium).navigateToApplyAdjustment().verifyAdjustBackdatedPermission().cancelAdjustment();
        loanTestHelper.repayLoan(systemDateTime.plusDays(11));
        loanTestHelper.setApplicationTime(systemDateTime.plusDays(12)).navigateBack();
        new LoanAccountPage(selenium).navigateToApplyAdjustment().verifyAdjustBackdatedPermissionOnRepay().cancelAdjustment();
        navigationHelper.navigateToAdminPage().navigateToViewRolesPage().navigateToManageRolePage("Admin").enablePermission("5_1_9").submitAndGotoViewRolesPage();
    }

    @SuppressWarnings("PMD.SignatureDeclareThrowsException")
    public void disableSystemInfoPermission() throws Exception {
        initRemote.dataLoadAndCacheRefresh(dbUnitUtilities, "acceptance_small_001_dbunit.xml", dataSource, selenium);
        AdminPage adminPage = navigationHelper.navigateToAdminPage();
        ViewRolesPage viewRolesPage = adminPage.navigateToViewRolesPage();
        ManageRolePage manageRolePage = viewRolesPage.navigateToManageRolePage("Admin");
        manageRolePage.verifyPage();
        manageRolePage.disablePermission("10_0");
        viewRolesPage = manageRolePage.submitAndGotoViewRolesPage();
        viewRolesPage.navigateToAdminPage();
        //try to reach System Info page, should fail
        adminPage = adminPage.failNavigationToSystemInfoPage();
     }
}
<commit_msg>Load a proper dataset in the setUp method.<commit_after>/*
 * Copyright Grameen Foundation USA
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * See also http://www.apache.org/licenses/LICENSE-2.0.html for an
 * explanation of the license and how it is applied.
 */

package org.mifos.test.acceptance.admin;


import org.joda.time.DateTime;
import org.mifos.framework.util.DbUnitUtilities;
import org.mifos.test.acceptance.framework.MifosPage;
import org.mifos.test.acceptance.framework.UiTestCaseBase;
import org.mifos.test.acceptance.framework.admin.AdminPage;
import org.mifos.test.acceptance.framework.admin.ManageRolePage;
import org.mifos.test.acceptance.framework.admin.ViewRolesPage;
import org.mifos.test.acceptance.framework.loan.LoanAccountPage;
import org.mifos.test.acceptance.framework.loanproduct.DefineNewLoanProductPage;
import org.mifos.test.acceptance.framework.office.OfficeParameters;
import org.mifos.test.acceptance.framework.testhelpers.LoanTestHelper;
import org.mifos.test.acceptance.framework.testhelpers.NavigationHelper;
import org.mifos.test.acceptance.loanproduct.LoanProductTestHelper;
import org.mifos.test.acceptance.remote.InitializeApplicationRemoteTestingService;
import org.mifos.test.acceptance.util.ApplicationDatabaseOperation;
import org.mifos.test.acceptance.util.TestDataSetup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

@ContextConfiguration(locations = { "classpath:ui-test-context.xml" })
@Test(sequential = true, groups = {"admin", "acceptance","ui"})
public class RolesAndPermissionTest extends UiTestCaseBase {

    private NavigationHelper navigationHelper;

    @Autowired
    private DriverManagerDataSource dataSource;
    @Autowired
    private DbUnitUtilities dbUnitUtilities;
    @Autowired
    private InitializeApplicationRemoteTestingService initRemote;
    private LoanTestHelper loanTestHelper;
    private LoanProductTestHelper loanProductTestHelper;
    private DateTime systemDateTime;
    @Autowired
    private ApplicationDatabaseOperation applicationDatabaseOperation;
    private final static String userLoginName = "test_user";
    private final static String officeName = "test_office";
    private final static String clientName = "test client";
    private final static String userName="test user";

    @Override
    @SuppressWarnings("PMD.SignatureDeclareThrowsException")    // one of the dependent methods throws Exception
    @BeforeMethod
    public void setUp() throws Exception {
        super.setUp();
        navigationHelper = new NavigationHelper(selenium);
        loanTestHelper = new LoanTestHelper(selenium);
        loanProductTestHelper = new LoanProductTestHelper(selenium);
        systemDateTime = new DateTime(2010, 10, 11, 10, 0, 0, 0);
        // TODO - some databases do not have customer status with Id = 3
        initRemote.dataLoadAndCacheRefresh(dbUnitUtilities, "acceptance_small_003_dbunit.xml", dataSource, selenium);
        TestDataSetup dataSetup = new TestDataSetup(selenium, applicationDatabaseOperation);
        loanTestHelper.setApplicationTime(systemDateTime);
        dataSetup.createBranch(OfficeParameters.BRANCH_OFFICE, officeName, "Off");
        dataSetup.createUser(userLoginName, userName, officeName);
        dataSetup.createClient(clientName, officeName, userName);
        dataSetup.addDecliningPrincipalBalance();
    }


    @AfterMethod
    public void tearDown() {
        (new MifosPage(selenium)).logout();
    }

    @SuppressWarnings("PMD.SignatureDeclareThrowsException")
    public void adjustmentOfPostDatedTransactions() throws Exception {
        navigationHelper.navigateToAdminPage().navigateToViewRolesPage().navigateToManageRolePage("Admin").disablePermission("5_1_9").
                verifyPermissionText("5_1_9", "Can adjust back dated transactions").submitAndGotoViewRolesPage();
        DefineNewLoanProductPage.SubmitFormParameters formParameters = loanProductTestHelper.defineLoanProductParameters(5,1000,20,DefineNewLoanProductPage.SubmitFormParameters.DECLINING_BALANCE_INTEREST_RECALCULATION);
        loanProductTestHelper.
                navigateToDefineNewLoanPangAndFillMandatoryFields(formParameters).
                submitAndGotoNewLoanProductPreviewPage().submit();
        loanTestHelper.createLoanAccount(clientName, formParameters.getOfferingName());
        loanTestHelper.approveLoan();
        loanTestHelper.disburseLoan(systemDateTime.plusDays(1));
        loanTestHelper.makePayment(systemDateTime.plusDays(10),"10");
        loanTestHelper.setApplicationTime(systemDateTime.plusDays(11)).navigateBack();
        new LoanAccountPage(selenium).navigateToApplyAdjustment().verifyAdjustBackdatedPermission().cancelAdjustment();
        loanTestHelper.repayLoan(systemDateTime.plusDays(11));
        loanTestHelper.setApplicationTime(systemDateTime.plusDays(12)).navigateBack();
        new LoanAccountPage(selenium).navigateToApplyAdjustment().verifyAdjustBackdatedPermissionOnRepay().cancelAdjustment();
        navigationHelper.navigateToAdminPage().navigateToViewRolesPage().navigateToManageRolePage("Admin").enablePermission("5_1_9").submitAndGotoViewRolesPage();
    }

    @SuppressWarnings("PMD.SignatureDeclareThrowsException")
    public void disableSystemInfoPermission() throws Exception {
        AdminPage adminPage = navigationHelper.navigateToAdminPage();
        ViewRolesPage viewRolesPage = adminPage.navigateToViewRolesPage();
        ManageRolePage manageRolePage = viewRolesPage.navigateToManageRolePage("Admin");
        manageRolePage.verifyPage();
        manageRolePage.disablePermission("10_0");
        viewRolesPage = manageRolePage.submitAndGotoViewRolesPage();
        viewRolesPage.navigateToAdminPage();
        //try to reach System Info page, should fail
        adminPage = adminPage.failNavigationToSystemInfoPage();
     }
}

{'fraction_non_alphanumeric': 0.08563410194174757, 'fraction_numerical': 0.007964199029126214, 'mean_word_length': 5.070441988950276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '144548', 'n_tokens_mistral': 3613, 'n_tokens_neox': 3510, 'n_words': 684}