Search in sources :

Example 1 with MockFormFile

use of org.mifos.reports.business.MockFormFile in project head by mifos.

the class BirtReportsUploadActionStrutsTest method testShouldSubmitSuccessAfterEdit.

@Test
public void testShouldSubmitSuccessAfterEdit() throws Exception {
    setRequestPathInfo("/birtReportsUploadAction.do");
    ReportsPersistence persistence = new ReportsPersistence();
    ReportsBO report = new ReportsBO();
    report.setReportName("testShouldSubmitSuccessAfterEdit");
    report.setReportsCategoryBO(persistence.getPersistentObject(ReportsCategoryBO.class, (short) 1));
    report.setIsActive((short) 1);
    short newActivityId = (short) legacyRolesPermissionsDao.calculateDynamicActivityId();
    legacyRolesPermissionsDao.createActivityForReports((short) 1, "test" + "testShouldSubmitSuccessAfterEdit");
    report.setActivityId(newActivityId);
    ReportsJasperMap reportJasperMap = report.getReportsJasperMap();
    reportJasperMap.setReportJasper("testFileName_EDIT.rptdesign");
    report.setReportsJasperMap(reportJasperMap);
    persistence.createOrUpdate(report);
    BirtReportsUploadActionForm editForm = new BirtReportsUploadActionForm();
    editForm.setReportId(report.getReportId().toString());
    editForm.setReportTitle("newTestShouldSubmitSuccessAfterEdit");
    editForm.setReportCategoryId("2");
    editForm.setIsActive("0");
    editForm.setFile(new MockFormFile("newTestShouldSubmitSuccessAfterEdit.rptdesign"));
    setActionForm(editForm);
    addRequestParameter("method", "editThenUpload");
    actionPerform();
    ReportsBO newReport = persistence.getReport(report.getReportId());
    Assert.assertEquals("newTestShouldSubmitSuccessAfterEdit", newReport.getReportName());
    Assert.assertEquals(2, newReport.getReportsCategoryBO().getReportCategoryId().shortValue());
    Assert.assertEquals(0, newReport.getIsActive().shortValue());
    Assert.assertEquals("newTestShouldSubmitSuccessAfterEdit.rptdesign", newReport.getReportsJasperMap().getReportJasper());
    ReportsJasperMap jasper = persistence.getPersistentObject(ReportsJasperMap.class, report.getReportsJasperMap().getReportId());
    Assert.assertEquals("newTestShouldSubmitSuccessAfterEdit.rptdesign", jasper.getReportJasper());
    removeReport(newReport.getReportId());
}
Also used : ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) MockFormFile(org.mifos.reports.business.MockFormFile) ReportsCategoryBO(org.mifos.reports.business.ReportsCategoryBO) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) ReportsBO(org.mifos.reports.business.ReportsBO) Test(org.junit.Test)

Example 2 with MockFormFile

use of org.mifos.reports.business.MockFormFile in project head by mifos.

the class BirtReportsUploadActionStrutsTest method testShouldSubmitSucessWhenUploadNewReport.

@Test
public void testShouldSubmitSucessWhenUploadNewReport() throws Exception {
    setRequestPathInfo("/birtReportsUploadAction.do");
    BirtReportsUploadActionForm form = new BirtReportsUploadActionForm();
    form.setReportTitle("testShouldSubmitSucessWhenUploadNewReport");
    form.setReportCategoryId("1");
    form.setIsActive("1");
    form.setFile(new MockFormFile("testFileName1.rptdesign"));
    setActionForm(form);
    addRequestParameter("method", "upload");
    actionPerform();
    ReportsBO report = (ReportsBO) request.getAttribute("report");
    Assert.assertNotNull(report);
    ReportsPersistence rp = new ReportsPersistence();
    ReportsJasperMap jasper = rp.getPersistentObject(ReportsJasperMap.class, report.getReportsJasperMap().getReportId());
    Assert.assertNotNull(jasper);
    verifyNoActionErrors();
    verifyForward("create_success");
    removeReport(report.getReportId());
}
Also used : MockFormFile(org.mifos.reports.business.MockFormFile) ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) ReportsBO(org.mifos.reports.business.ReportsBO) Test(org.junit.Test)

Example 3 with MockFormFile

use of org.mifos.reports.business.MockFormFile in project head by mifos.

the class BirtReportsUploadActionStrutsTest method testShouldCreateFailureWhenActivityIdOutOfRange.

@Test
public void testShouldCreateFailureWhenActivityIdOutOfRange() throws Exception {
    ActivityEntity activityEntity = insertActivityForTest(Short.MIN_VALUE);
    FormFile file = new MockFormFile("testFilename");
    BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
    setRequestPathInfo("/birtReportsUploadAction.do");
    addRequestParameter("method", "upload");
    actionForm.setFile(file);
    actionForm.setReportTitle("existingTitle");
    actionForm.setReportCategoryId("1");
    actionForm.setIsActive("1");
    setActionForm(actionForm);
    actionPerform();
    verifyForward("preview_failure");
    String[] errors = { ReportsConstants.ERROR_NOMOREDYNAMICACTIVITYID };
    verifyActionErrors(errors);
    deleteActivityForTest(activityEntity);
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MockFormFile(org.mifos.reports.business.MockFormFile) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) FormFile(org.apache.struts.upload.FormFile) MockFormFile(org.mifos.reports.business.MockFormFile) Test(org.junit.Test)

Example 4 with MockFormFile

use of org.mifos.reports.business.MockFormFile in project head by mifos.

the class BirtReportsUploadActionStrutsTest method testUpgradePathNotRuined.

@Test
public void testUpgradePathNotRuined() throws Exception {
    // TODO Temporary solution to avoid unsuccessful test on some machines
    // Retrieve initial activities information
    List<ActivityEntity> activities = new RolesPermissionsBusinessService().getActivities();
    int newActivityId = activities.get(activities.size() - 1).getId() + 1;
    // Upload a report creating an activity for the report
    FormFile file = new MockFormFile("testFilename.rptdesign");
    BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
    setRequestPathInfo("/birtReportsUploadAction.do");
    addRequestParameter("method", "upload");
    actionForm.setFile(file);
    actionForm.setReportTitle("exsitTitle");
    actionForm.setReportCategoryId("1");
    actionForm.setIsActive("1");
    setActionForm(actionForm);
    actionPerform();
    Assert.assertEquals(0, getErrorSize());
    Assert.assertNotNull(request.getAttribute("report"));
    // Simulate an future activities upgrade
    AddActivity activity = null;
    try {
        activity = new AddActivity((short) newActivityId, SecurityConstants.ORGANIZATION_MANAGEMENT, "no name");
        activity.upgrade(StaticHibernateUtil.getSessionTL().connection());
    } catch (Exception e) {
        legacyRolesPermissionsDao.delete(request.getAttribute("report"));
        StaticHibernateUtil.flushSession();
        throw e;
    }
    // Undo
    ReportsBO report = (ReportsBO) request.getAttribute("report");
    removeReport(report.getReportId());
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MockFormFile(org.mifos.reports.business.MockFormFile) AddActivity(org.mifos.security.AddActivity) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FormFile(org.apache.struts.upload.FormFile) MockFormFile(org.mifos.reports.business.MockFormFile) ReportsBO(org.mifos.reports.business.ReportsBO) Test(org.junit.Test)

Example 5 with MockFormFile

use of org.mifos.reports.business.MockFormFile in project head by mifos.

the class BirtReportsUploadActionStrutsTest method testShouldPreviewSuccessWithReportTemplate.

@Test
public void testShouldPreviewSuccessWithReportTemplate() throws Exception {
    setRequestPathInfo("/birtReportsUploadAction.do");
    BirtReportsUploadActionForm form = new BirtReportsUploadActionForm();
    form.setFile(new MockFormFile("testFileName1.rptdesign"));
    form.setIsActive("1");
    form.setReportCategoryId("1");
    form.setReportTitle("testReportTitle1");
    setActionForm(form);
    addRequestParameter("method", "preview");
    actionPerform();
    verifyNoActionErrors();
    verifyForward("preview_success");
}
Also used : MockFormFile(org.mifos.reports.business.MockFormFile) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 MockFormFile (org.mifos.reports.business.MockFormFile)6 BirtReportsUploadActionForm (org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm)5 ReportsBO (org.mifos.reports.business.ReportsBO)3 ReportsJasperMap (org.mifos.reports.business.ReportsJasperMap)3 ReportsPersistence (org.mifos.reports.persistence.ReportsPersistence)3 FormFile (org.apache.struts.upload.FormFile)2 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)2 IOException (java.io.IOException)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1 AdminDocumentBO (org.mifos.reports.admindocuments.business.AdminDocumentBO)1 BirtAdminDocumentUploadActionForm (org.mifos.reports.admindocuments.struts.actionforms.BirtAdminDocumentUploadActionForm)1 ReportsCategoryBO (org.mifos.reports.business.ReportsCategoryBO)1 AddActivity (org.mifos.security.AddActivity)1 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)1