Search in sources :

Example 1 with ClassRelativeResourceLoader

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

the class EmbeddedDatabaseBuilderTests method createSameSchemaTwiceWithoutUniqueDbNames.

@Test
public void createSameSchemaTwiceWithoutUniqueDbNames() throws Exception {
    EmbeddedDatabase db1 = //
    new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())).addScripts("db-schema-without-dropping.sql").build();
    try {
        //
        new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())).addScripts("db-schema-without-dropping.sql").build();
        fail("Should have thrown a ScriptStatementFailedException");
    } catch (ScriptStatementFailedException e) {
    // expected
    } finally {
        db1.shutdown();
    }
}
Also used : ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) ScriptStatementFailedException(org.springframework.jdbc.datasource.init.ScriptStatementFailedException) Test(org.junit.Test)

Example 2 with ClassRelativeResourceLoader

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

the class EmbeddedDatabaseBuilderTests method createSameSchemaTwiceWithGeneratedUniqueDbNames.

@Test
public void createSameSchemaTwiceWithGeneratedUniqueDbNames() throws Exception {
    EmbeddedDatabase db1 = // 
    new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())).addScripts("db-schema-without-dropping.sql", // 
    "db-test-data.sql").generateUniqueName(// 
    true).build();
    JdbcTemplate template1 = new JdbcTemplate(db1);
    assertNumRowsInTestTable(template1, 1);
    template1.update("insert into T_TEST (NAME) values ('Sam')");
    assertNumRowsInTestTable(template1, 2);
    EmbeddedDatabase db2 = // 
    new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())).addScripts("db-schema-without-dropping.sql", // 
    "db-test-data.sql").generateUniqueName(// 
    true).build();
    assertDatabaseCreated(db2);
    db1.shutdown();
    db2.shutdown();
}
Also used : ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test)

Example 3 with ClassRelativeResourceLoader

use of org.springframework.core.io.ClassRelativeResourceLoader in project uPortal by Jasig.

the class PipelineStylesheetTest method setup.

@Before
public void setup() throws Exception {
    this.resourceLoader = new ClassRelativeResourceLoader(getClass());
    templatesBuilder = new TemplatesBuilder();
    templatesBuilder.setResourceLoader(this.resourceLoader);
}
Also used : TemplatesBuilder(org.apereo.portal.utils.cache.resource.TemplatesBuilder) ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) Before(org.junit.Before)

Example 4 with ClassRelativeResourceLoader

use of org.springframework.core.io.ClassRelativeResourceLoader in project uPortal by Jasig.

the class XalanMessageHelperTest method setup.

@Before
public void setup() throws Exception {
    final ResourceLoaderURIResolver resolver = new ResourceLoaderURIResolver(new ClassRelativeResourceLoader(getClass()));
    this.tFactory = TransformerFactory.newInstance();
    this.tFactory.setURIResolver(resolver);
    this.tFactory.setErrorListener(new SimpleTransformErrorListener(LogFactory.getLog(getClass())));
    this.xmlSource = new StreamSource(this.getClass().getResourceAsStream("test.xml"));
}
Also used : ResourceLoaderURIResolver(org.apereo.portal.xml.ResourceLoaderURIResolver) ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) SimpleTransformErrorListener(org.springframework.util.xml.SimpleTransformErrorListener) StreamSource(javax.xml.transform.stream.StreamSource) Before(org.junit.Before)

Example 5 with ClassRelativeResourceLoader

use of org.springframework.core.io.ClassRelativeResourceLoader in project uPortal by Jasig.

the class XsltPortalUrlProviderTest method setup.

@Before
public void setup() throws Exception {
    final ResourceLoaderURIResolver resolver = new ResourceLoaderURIResolver(new ClassRelativeResourceLoader(getClass()));
    this.tFactory = TransformerFactory.newInstance();
    this.tFactory.setURIResolver(resolver);
    this.tFactory.setErrorListener(new SimpleTransformErrorListener(LogFactory.getLog(getClass())));
    // Load the XML document so it reads the same way the rendering pipeline reads XML
    final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
    final XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(this.getClass().getResourceAsStream("test.xml"));
    final XMLStreamReader streamReader = new FixedXMLEventStreamReader(eventReader);
    xmlSource = new StAXSource(streamReader);
    xslTemplate = tFactory.newTemplates(new StreamSource(this.getClass().getResourceAsStream("test.xsl")));
    expected = IOUtils.toString(this.getClass().getResourceAsStream("result.xml"));
}
Also used : ResourceLoaderURIResolver(org.apereo.portal.xml.ResourceLoaderURIResolver) ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) XMLStreamReader(javax.xml.stream.XMLStreamReader) SimpleTransformErrorListener(org.springframework.util.xml.SimpleTransformErrorListener) FixedXMLEventStreamReader(org.springframework.util.xml.FixedXMLEventStreamReader) StreamSource(javax.xml.transform.stream.StreamSource) XMLEventReader(javax.xml.stream.XMLEventReader) StAXSource(javax.xml.transform.stax.StAXSource) XMLInputFactory(javax.xml.stream.XMLInputFactory) Before(org.junit.Before)

Aggregations

ClassRelativeResourceLoader (org.springframework.core.io.ClassRelativeResourceLoader)41 Resource (org.springframework.core.io.Resource)34 ResourceLoader (org.springframework.core.io.ResourceLoader)34 Test (org.junit.Test)33 File (java.io.File)32 Before (org.junit.Before)5 StreamSource (javax.xml.transform.stream.StreamSource)4 ResourceLoaderURIResolver (org.apereo.portal.xml.ResourceLoaderURIResolver)4 SimpleTransformErrorListener (org.springframework.util.xml.SimpleTransformErrorListener)4 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 MessagingException (javax.mail.MessagingException)2 MimeMessage (javax.mail.internet.MimeMessage)2 JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)2 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)2 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1