Example usage for org.springframework.core.io ClassPathResource ClassPathResource

List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource ClassPathResource.

Prototype

public ClassPathResource(String path, @Nullable Class<?> clazz) 

Source Link

Document

Create a new ClassPathResource for Class usage.

Usage

From source file:me.philnate.textmanager.utils._WordCount.java

@Test
public void testSmallDoc() throws FileNotFoundException, IOException {
    assertEquals(8, WordCount.countFile(new ClassPathResource("docs/short.doc", loader).getFile()));
}

From source file:com.mymita.vaadlets.demo.AddonDemoApplication.java

private static void fillEditorWithDefaultXML(final VaadletsBuilder vaadlets) {
    vaadlets.<Panel>getComponent("content").getContent().removeAllComponents();
    final TextField editor = vaadlets.getComponent("editor");
    try {/*from w  ww  .  j a v  a2s . c  o m*/
        editor.setValue(CharStreams.toString(new InputStreamReader(
                new ClassPathResource("startingPoint.xml", AddonDemoApplication.class).getInputStream(),
                "UTF-8")));
    } catch (final IOException e) {
    }
}

From source file:me.springframework.di.spring.FactoryMethodTest.java

@BeforeClass
public static void setUp() {
    Resource resource = new ClassPathResource("/factorymethod.xml", FactoryMethodTest.class);
    configuration = readConfiguration(resource);
}

From source file:com.obergner.hzserver.pluggable.ComposableXmlConfigFactoryBeanTest.java

private ComposableXmlConfigFactoryBean newObjectUnderTest() {
    final ComposableXmlConfigFactoryBean objectUnderTest = new ComposableXmlConfigFactoryBean();
    objectUnderTest.setGlobalXmlConfigFile(new ClassPathResource(CONFIG_FILE, getClass()));
    objectUnderTest.setDataRootDirectory(new ClassPathResource("data/subdir/", getClass()));
    objectUnderTest.setDataFileSuffix(".xml");
    return objectUnderTest;
}

From source file:com.springsource.greenhouse.database.GreenhouseTestDatabaseBuilder.java

public GreenhouseTestDatabaseBuilder activity() {
    populator.addScript(new ClassPathResource("install/Activity.sql", DatabaseUpgrader.class));
    return this;
}

From source file:org.hephaestus.fixedformat.impl.TestRecordFactoryBase.java

protected void setUp() throws Exception {
    // Load the application context
    BeanFactory bf = new XmlBeanFactory(new ClassPathResource("/TestRecordFactoryBaseContext.xml", getClass()));

    recordFactory = (RecordFactory) bf.getBean("TestFactory");
}

From source file:me.philnate.textmanager.utils._WordCount.java

@Test
public void testSmallDocX() throws FileNotFoundException, IOException {
    assertEquals(8, WordCount.countFile(new ClassPathResource("docs/short.docx", loader).getFile()));

}

From source file:edu.unc.lib.dl.schematron.SchematronValidatorTest.java

/**
 * Tests that the expected output from the forms app should be valid.
 *///from www.j av a  2 s  .  co m
@Test
public void testGoodSimpleForm() {

    SchematronValidator sv = new SchematronValidator();
    sv.loadSchemas();

    ClassPathResource test = new ClassPathResource("simple_mets_profile.sch", SchematronValidator.class);
    sv.getSchemas().put("test", test);
    sv.loadSchemas();

    ClassPathResource bad = new ClassPathResource("/samples/good-simple-form.xml", SchematronValidator.class);

    try {
        boolean valid = sv.isValid(bad, "test");
        Document output = sv.validate(bad, "test");
        XMLOutputter dbout = new XMLOutputter();
        dbout.setFormat(Format.getPrettyFormat());
        log.info(dbout.outputString(output));
        assertTrue("This XML should be valid according to the schema", valid);
    } catch (IOException e) {
        fail("Got exception" + e.getMessage());
    }

}

From source file:org.beanio.spring.BeanIOFlatFileItemReaderTest.java

@Test(expected = ItemStreamException.class)
public void testInputFileNotFoundAndStrict() throws Exception {
    BeanIOFlatFileItemReader<Object> reader = new BeanIOFlatFileItemReader<Object>();
    reader.setStreamName("stream1");
    reader.setStreamMapping(new ClassPathResource("spring_mapping1.xml", getClass()));
    reader.setResource(new ClassPathResource("doesnotexist.txt", getClass()));
    reader.afterPropertiesSet();/*w  ww .ja v a 2  s  . c  o  m*/
    reader.open(new ExecutionContext());
}

From source file:example.xmlbeam.XmlBeamExampleTests.java

private static MockHttpServletRequestBuilder buildXmlPostRequestFor(String filename) throws Exception {

    Path path = Paths.get(new ClassPathResource(filename, XmlBeamExampleTests.class).getURI());

    return post("/customers").//
            content(Files.readAllBytes(path)).//
            contentType(MediaType.APPLICATION_XML);
}