Search in sources :

Example 26 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-boot by spring-projects.

the class SpringPackageScanClassResolver method scan.

private Resource[] scan(ClassLoader loader, String packageName) throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(loader);
    String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(packageName) + "/**/*.class";
    Resource[] resources = resolver.getResources(pattern);
    return resources;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 27 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testExample2.

@Test
public void testExample2() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/orm/jpa/persistence-example2.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertNotNull(info);
    assertEquals(1, info.length);
    assertEquals("OrderManagement2", info[0].getPersistenceUnitName());
    assertEquals(1, info[0].getMappingFileNames().size());
    assertEquals("mappings.xml", info[0].getMappingFileNames().get(0));
    assertEquals(0, info[0].getProperties().keySet().size());
    assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses());
}
Also used : JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) Test(org.junit.Test)

Example 28 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testMetaInfCase.

@Test
public void testMetaInfCase() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertNotNull(info);
    assertEquals(1, info.length);
    assertEquals("OrderManagement", info[0].getPersistenceUnitName());
    assertEquals(2, info[0].getJarFileUrls().size());
    assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0));
    assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1));
    assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses());
}
Also used : JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 29 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testInvalidPersistence.

// not doing schema parsing anymore for JPA 2.0 compatibility
@Ignore
@Test
public void testInvalidPersistence() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/orm/jpa/persistence-invalid.xml";
    try {
        reader.readPersistenceUnitInfos(resource);
        fail("expected invalid document exception");
    } catch (RuntimeException expected) {
    }
}
Also used : JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testJpa1ExcludeUnlisted.

@Test
public void testJpa1ExcludeUnlisted() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/orm/jpa/persistence-exclude-1.0.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertNotNull(info);
    assertEquals("The number of persistence units is incorrect.", 4, info.length);
    PersistenceUnitInfo noExclude = info[0];
    assertNotNull("noExclude should not be null.", noExclude);
    assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName());
    assertFalse("Exclude unlisted should default false in 1.0.", noExclude.excludeUnlistedClasses());
    PersistenceUnitInfo emptyExclude = info[1];
    assertNotNull("emptyExclude should not be null.", emptyExclude);
    assertEquals("emptyExclude name is not correct.", "EmptyExcludeElement", emptyExclude.getPersistenceUnitName());
    assertTrue("emptyExclude should be true.", emptyExclude.excludeUnlistedClasses());
    PersistenceUnitInfo trueExclude = info[2];
    assertNotNull("trueExclude should not be null.", trueExclude);
    assertEquals("trueExclude name is not correct.", "TrueExcludeElement", trueExclude.getPersistenceUnitName());
    assertTrue("trueExclude should be true.", trueExclude.excludeUnlistedClasses());
    PersistenceUnitInfo falseExclude = info[3];
    assertNotNull("falseExclude should not be null.", falseExclude);
    assertEquals("falseExclude name is not correct.", "FalseExcludeElement", falseExclude.getPersistenceUnitName());
    assertFalse("falseExclude should be false.", falseExclude.excludeUnlistedClasses());
}
Also used : JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) Test(org.junit.Test)

Aggregations

PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)34 Resource (org.springframework.core.io.Resource)22 Test (org.junit.Test)15 IOException (java.io.IOException)11 JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)11 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)10 File (java.io.File)9 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)9 ClassPathResource (org.springframework.core.io.ClassPathResource)7 ArrayList (java.util.ArrayList)6 FileOutputStream (java.io.FileOutputStream)4 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)4 UrlResource (org.springframework.core.io.UrlResource)3 URL (java.net.URL)2 Properties (java.util.Properties)2 DataSource (javax.sql.DataSource)2 Ignore (org.junit.Ignore)2 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)2 LangDetectException (com.cybozu.labs.langdetect.LangDetectException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1