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) 

Source Link

Document

Create a new ClassPathResource for ClassLoader usage.

Usage

From source file:org.localmatters.serializer.tool.ConfigWriterFromClassTest.java

/**
 * Tests getting the configuration for the <code>ObjectWithGenerics</code>
 * class/*from   ww w .  j  a va 2  s .co  m*/
 */
public void testConfigForObjectWithGenerics() throws Exception {
    Resource resource = new ClassPathResource("test-object-with-generics-config.xml");
    assertEquals(resourceToString(resource),
            ConfigWriterFromClass.getConfiguration(ObjectWithGenerics.class.getName()));
}

From source file:com.enonic.cms.itest.content.imports.Support112124Test.java

@Before
public void setUp() throws IOException {
    String kontaktContentTypeXml = resourceToString(new ClassPathResource(
            Support112124Test.class.getName().replace(".", "/") + "-innholdstype-kontakt.xml"));
    String statistikkContentTypeXml = resourceToString(new ClassPathResource(
            Support112124Test.class.getName().replace(".", "/") + "-innholdstype-statistikk.xml"));

    DomainFactory factory = fixture.getFactory();

    fixture.initSystemData();//from  www  .  j a  v  a2  s  .  c o  m

    fixture.createAndStoreNormalUserWithUserGroup("testuser", "Test user", "testuserstore");

    fixture.save(
            factory.createContentHandler("MyHandler", ContentHandlerName.CUSTOM.getHandlerClassShortName()));

    fixture.save(factory.createContentType("kontaktCty", ContentHandlerName.CUSTOM.getHandlerClassShortName(),
            XMLDocumentFactory.create(kontaktContentTypeXml).getAsJDOMDocument()));
    fixture.save(
            factory.createContentType("statistikkCty", ContentHandlerName.CUSTOM.getHandlerClassShortName(),
                    XMLDocumentFactory.create(statistikkContentTypeXml).getAsJDOMDocument()));

    fixture.save(factory.createUnit("MyUnit"));
    fixture.save(factory.createCategory("Kontakt", null, "kontaktCty", "MyUnit", "testuser", "testuser"));
    fixture.save(factory.createCategoryAccessForUser("Kontakt", "testuser", "read, create, approve"));

    fixture.save(factory.createCategory("Statistikk", null, "statistikkCty", "MyUnit", "testuser", "testuser"));
    fixture.save(factory.createCategoryAccessForUser("Statistikk", "testuser", "read, create, approve"));

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("127.0.0.1");
    ServletRequestAccessor.setRequest(request);

    PortalSecurityHolder.setLoggedInUser(fixture.findUserByName("testuser").getKey());
    PortalSecurityHolder.setImpersonatedUser(fixture.findUserByName("testuser").getKey());

    ImportJobFactory.setExecuteInOneTransaction(true);
}

From source file:se.inera.axel.shs.camel.DefaultCamelShsMessageConverterTest.java

@DirtiesContext
@Test//w ww .  j a  v  a  2 s .com
public void convertXmlStreamToShsMessage() throws Exception {

    resultEndpoint.expectedMessageCount(1);

    Resource xmlResource = new ClassPathResource("se/inera/axel/shs/camel/xmlFile.xml");

    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(ShsHeaders.FROM, DEFAULT_TEST_FROM);
    headers.put(ShsHeaders.TO, DEFAULT_TEST_TO);
    headers.put(ShsHeaders.SUBJECT, DEFAULT_TEST_SUBJECT);
    headers.put(ShsHeaders.PRODUCT_ID, DEFAULT_TEST_PRODUCT_ID);
    headers.put(ShsHeaders.DATAPART_CONTENTTYPE, "text/xml");
    headers.put(ShsHeaders.DATAPART_FILENAME, "MyXmlFile.xml");
    headers.put(ShsHeaders.DATAPART_CONTENTLENGTH, xmlResource.contentLength());
    headers.put(ShsHeaders.DATAPART_TYPE, "xml");

    template.sendBodyAndHeaders("direct:camelToShsConverter", xmlResource.getInputStream(), headers);

    resultEndpoint.assertIsSatisfied();
    List<Exchange> exchanges = resultEndpoint.getExchanges();
    Exchange exchange = exchanges.get(0);
    Message in = exchange.getIn();
    ShsMessage shsMessage = in.getMandatoryBody(ShsMessage.class);

    List<DataPart> dataParts = shsMessage.getDataParts();
    Assert.assertNotNull(dataParts);
    Assert.assertEquals(dataParts.size(), 1);

    DataPart dataPart = dataParts.get(0);
    Assert.assertEquals(dataPart.getFileName(), "MyXmlFile.xml");
    Assert.assertEquals(dataPart.getDataPartType(), "xml");
    Assert.assertEquals((long) dataPart.getContentLength(), xmlResource.contentLength());

    Assert.assertEquals(IOUtils.toString(dataPart.getDataHandler().getInputStream()),
            IOUtils.toString(xmlResource.getInputStream()));

}

From source file:org.deeplearning4j.cli.schemes.BaseSchemeTest.java

@Test
public void testScheme() throws Exception {
    Scheme scheme = getScheme();//from  w  w w .ja v  a 2  s. c o m
    RecordReader recordReader = scheme.createReader(new ClassPathResource("iris.txt").getURI());

    assertTrue(recordReader.hasNext());
    while (recordReader.hasNext()) {
        Collection<Writable> record = recordReader.next();
        assertEquals(1, record.size());
    }

    recordReader = scheme.createReader(new ClassPathResource("iris.txt").getURI());

    List<Collection<Writable>> records = new ArrayList<>();
    int count = 0;
    RecordWriter writer = scheme.createWriter(URI.create("test_out.txt"));

    for (Collection<Writable> record : records) {
        writer.write(record);
        assertEquals(1, record.size());
    }

    recordReader = scheme.createReader(URI.create("test_out.txt"));

    while (recordReader.hasNext()) {
        Collection<Writable> record = recordReader.next();
        records.add(record);
        assertEquals(1, record.size());
        count++;
    }

    assertEquals(1, count);
    writer.close();
}

From source file:com.google.enterprise.connector.filenet4.FileNetConnectorFactory.java

/**
 * Creates a connector instance by loading the bean definitions and creating
 * the connector bean instance using Spring      *
 *
 *  @see com.google.enterprise.connector.spi.ConnectorFactory#makeConnector(java.util.Map)
 **///from  ww w .j  a  v a2  s. c o m

@Override
public Connector makeConnector(Map<String, String> config) throws RepositoryException {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(factory);
    Resource connectorInstanceConfig = new ClassPathResource(CONNECTOR_DEFAULTS_XML);
    Resource connectorDefaultsConfig = new ClassPathResource(CONNECTOR_INSTANCE_XML);
    beanReader.loadBeanDefinitions(connectorInstanceConfig);
    beanReader.loadBeanDefinitions(connectorDefaultsConfig);
    Properties props = new Properties();
    props.putAll(config);
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    configurer.setProperties(props);
    configurer.postProcessBeanFactory(factory);
    Connector connector = (Connector) factory.getBean("Filenet_P8");
    if (connector == null) {
        throw new RepositoryException("Filenet_P8 bean could not be loaded");
    }
    return connector;
}

From source file:it.inserpio.mapillary.gopro.importer.parser.bikematepro.parser.impl.BikeMateProGPXParser.java

@Override
public List<GPXDateTimePoint> parse(File GPXFile)
        throws GPXParsingException, XmlMappingException, IOException, ParseException {
    CastorMarshaller castorMarshaller = new CastorMarshaller();

    Resource mappingLocation = new ClassPathResource("bike-mate-pro-mapping.xml");

    castorMarshaller.setMappingLocation(mappingLocation);
    castorMarshaller.afterPropertiesSet();

    Source GPXSource = new StreamSource(new FileInputStream(GPXFile));

    BikeMateProGPX bikeMateProGPX = (BikeMateProGPX) castorMarshaller.unmarshal(GPXSource);

    return BikeMateProGPXTransformer.translate(bikeMateProGPX);
}

From source file:org.cloudfoundry.caldecott.client.TunnelHelper.java

public static void deployTunnelApp(CloudFoundryClient client) {
    ClassPathResource cpr = new ClassPathResource("caldecott_helper.zip");
    try {/*from  ww  w  .j a v a 2  s. co m*/
        File temp = copyCaldecottZipFile(cpr);
        client.createApplication(TUNNEL_APP_NAME, new Staging("ruby19", "sinatra"), 64,
                Arrays.asList(getRandomUrl(client, TUNNEL_APP_NAME)), Arrays.asList(new String[] {}), false);
        client.uploadApplication(TUNNEL_APP_NAME, temp);
        client.updateApplicationEnv(TUNNEL_APP_NAME,
                Collections.singletonMap("CALDECOTT_AUTH", UUID.randomUUID().toString()));
        client.startApplication(TUNNEL_APP_NAME);
        temp.delete();
    } catch (IOException e) {
        throw new TunnelException("Unable to deploy the Caldecott server application", e);
    }
}

From source file:org.energyos.espi.thirdparty.mocks.MockRestTemplate.java

@SuppressWarnings("unchecked")
@Override// www  .j a  v  a  2 s.co  m
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
        Class<T> responseType, Object... uriVariables) throws RestClientException {
    ClassPathResource sourceFile = new ClassPathResource("/fixtures/test_usage_data.xml");
    String inputStreamString;
    try {
        inputStreamString = new Scanner(sourceFile.getInputStream(), "UTF-8").useDelimiter("\\A").next();
        return new ResponseEntity<>((T) inputStreamString, HttpStatus.OK);
    } catch (IOException e) {
        e.printStackTrace();
        throw new RestClientException("The file import broke.");
    }
}

From source file:org.wso2.carbon.metrics.impl.JDBCCleanupTest.java

@BeforeClass
public static void setupDatasource() throws ScriptException, SQLException {
    dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test-cleanup;DB_CLOSE_DELAY=-1", "sa", "");
    template = new JdbcTemplate(dataSource);
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("dbscripts/h2.sql"));
    populator.populate(dataSource.getConnection());
}

From source file:jp.primecloud.auto.util.JSchUtilsTest.java

@Test
@Ignore/*from  w w  w . j  a  v  a  2s  .c  o  m*/
public void testExecuteCommand2() throws Exception {
    // ????
    File privateKeyFile = new ClassPathResource(
            ClassUtils.addResourcePathToPackagePath(getClass(), "key01.pem")).getFile();
    String privateKey = FileUtils.readFileToString(privateKeyFile, "UTF-8");

    Session session = JSchUtils.createSessionByPrivateKey("user01", privateKey, "172.22.0.23");

    JSchResult result = JSchUtils.executeCommand(session, "env", "UTF-8");
    assertEquals(0, result.getExitStatus());

    result = JSchUtils.executeCommand(session, "ls -l /etc", "UTF-8");
    assertEquals(0, result.getExitStatus());

    session.disconnect();
}