Search in sources :

Example 6 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project head by mifos.

the class MifosMockStrutsTestCase method setStrutsConfig.

protected void setStrutsConfig() throws IOException {
    /*
         * Add a pointer to the context directory so that the web.xml file can be located when running test cases using
         * the junit plugin inside Eclipse.
         * 
         * Find the Web Resources dir (where WEB-INF lives) via Classpath, not hard-coded filenames.
         */
    Resource r = new ClassPathResource("META-INF/resources/WEB-INF/struts-config.xml");
    if (!r.exists() || !r.isReadable()) {
        fail(r.getDescription() + " does not exist or is not readable");
    }
    File webResourcesDirectory = r.getFile().getParentFile().getParentFile();
    mockStruts.setContextDirectory(webResourcesDirectory);
    setConfigFile("/WEB-INF/struts-config.xml,/WEB-INF/other-struts-config.xml");
    /*
         * Because there is no more old-style web.xml as strutstest expects, we simply hard-code our ActionServlet
         * (actually our new ActionServlet30).
         * 
         * Because web.xml (now web-fragment.xml) isn't actually read, the ActionServlet is not initialized with servlet
         * init-params config for all /WEB-INF/*-struts-config.xml listed in web(-fragment).xml, nor are the
         * context-param read into config initParameter from web.xml by the MockStrutsTestCase. All Mifos *StrutsTest
         * don't seem to need that though, and pass with this.
         */
    mockStruts.setActionServlet(new ActionServlet30());
    request = mockStruts.getMockRequest();
    context = mockStruts.getMockContext();
}
Also used : ActionServlet30(org.mifos.framework.struts.ActionServlet30) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 7 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project head by mifos.

the class BranchCashConfirmationConfigServiceTest method setUp.

@Override
protected void setUp() throws Exception {
    Resource branchCashConfirmationReportConfig = new ClassPathResource(FilePaths.HO_CASH_CONFIRMATION_REPORT_CONFIG);
    hOCashConfirmationConfigService = new HOCashConfirmationConfigService(branchCashConfirmationReportConfig);
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 8 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project head by mifos.

the class ReportProductOfferingServiceIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    loanPrdBusinessServiceMock = createMock(LoanPrdBusinessService.class);
    savingsProductBusinessServiceMock = createMock(SavingsPrdBusinessService.class);
    reportProductOfferingConfig = new ClassPathResource(FilePaths.REPORT_PRODUCT_OFFERING_CONFIG);
    reportProductOfferingService = new ReportProductOfferingService(loanPrdBusinessServiceMock, savingsProductBusinessServiceMock, reportProductOfferingConfig) {

        @Override
        protected Short getLoanProduct1() {
            return LOAN_OFFERING_1_ID;
        }

        @Override
        protected Short getLoanProduct2() {
            return LOAN_OFFERING_2_ID;
        }

        @Override
        protected Short getSavingsProduct1() {
            return SAVINGS_OFFERING_1_ID;
        }

        @Override
        protected Short getSavingsProduct2() {
            return SAVINGS_OFFERING_2_ID;
        }
    };
}
Also used : LoanPrdBusinessService(org.mifos.accounts.productdefinition.business.service.LoanPrdBusinessService) SavingsPrdBusinessService(org.mifos.accounts.productdefinition.business.service.SavingsPrdBusinessService) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

Example 9 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project head by mifos.

the class DbUnitUtilities method getDataSetFromClasspathFile.

public IDataSet getDataSetFromClasspathFile(String filename, String directory) throws IOException, DataSetException {
    ClassPathResource resource = new ClassPathResource(directory + filename);
    File file = resource.getFile();
    if (file == null) {
        throw new FileNotFoundException("Couldn't find file:" + filename);
    }
    FlatXmlDataSetBuilder fb = new FlatXmlDataSetBuilder();
    fb.setColumnSensing(true);
    fb.setDtdMetadata(false);
    return fb.build(file);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 10 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project head by mifos.

the class RESTAPITestHelper method getJSONFromDataSet.

public String getJSONFromDataSet(String apiType, String by, String apiValue) throws IOException {
    String type = apiType.replace('/', '-');
    String value = apiValue.replace('/', '-');
    String path = String.format("/dataSets/rest/%s-%s-%s.json", type, by, value);
    ClassPathResource resource = new ClassPathResource(path);
    File file = resource.getFile();
    if (file == null) {
        throw new FileNotFoundException("Couldn't find file");
    }
    return FileUtil.readAsString(file);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

ClassPathResource (org.springframework.core.io.ClassPathResource)1441 Test (org.junit.jupiter.api.Test)558 Resource (org.springframework.core.io.Resource)314 Test (org.junit.Test)274 lombok.val (lombok.val)159 List (java.util.List)137 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)129 IOException (java.io.IOException)118 InputStream (java.io.InputStream)105 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)104 File (java.io.File)91 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)87 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)78 ArrayList (java.util.ArrayList)77 Bean (org.springframework.context.annotation.Bean)61 FileSystemResource (org.springframework.core.io.FileSystemResource)61 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)60 Path (java.nio.file.Path)51 Map (java.util.Map)47 BeforeEach (org.junit.jupiter.api.BeforeEach)45