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.jasig.schedassist.impl.caldav.xml.ReportResponseHandlerImplTest.java

@Test
public void testControl() throws IOException {
    Resource controlExample = new ClassPathResource("caldav-examples/report-response-single-calendar.xml");

    ReportResponseHandlerImpl handler = new ReportResponseHandlerImpl();
    List<CalendarWithURI> calendars = handler.extractCalendars(controlExample.getInputStream());
    Assert.assertEquals(1, calendars.size());

    CalendarWithURI withUri = calendars.get(0);
    Assert.assertEquals("http://cal.example.com/bernard/work/abcd2.ics", withUri.getUri());
    Assert.assertEquals("\"fffff-abcd2\"", withUri.getEtag());
    Calendar cal = withUri.getCalendar();
    ProdId prodId = cal.getProductId();//from  ww w.j a v a 2 s  .c  om
    Assert.assertNotNull(prodId);
    Assert.assertEquals("-//CalendarKey 2.0//iCal4j 1.0//EN", prodId.getValue());

    ComponentList components = cal.getComponents(VEvent.VEVENT);
    Assert.assertEquals(1, components.size());
    VEvent event = (VEvent) components.get(0);
    Assert.assertEquals("regular 10 am meeting", event.getSummary().getValue());
}

From source file:org.canova.api.records.reader.impl.LibSvmTest.java

@Test
public void testReadWrite() throws Exception {
    Configuration conf = new Configuration();
    conf.set(FileRecordReader.APPEND_LABEL, "true");
    File out = new File("iris.libsvm.out");
    conf.set(FileRecordWriter.PATH, out.getAbsolutePath());
    RecordReader libSvmRecordReader = new LibSvmRecordReader();
    libSvmRecordReader.initialize(conf, new FileSplit(new ClassPathResource("iris.libsvm").getFile()));

    List<String> assertion = IOUtils.readLines(new ClassPathResource("iris.libsvm").getInputStream());
    RecordWriter writer = new LibSvmRecordWriter();
    writer.setConf(conf);/*from w  w  w  .ja  va2  s  .c o  m*/
    Collection<Collection<Writable>> data = new ArrayList<>();
    while (libSvmRecordReader.hasNext()) {
        Collection<Writable> record = libSvmRecordReader.next();
        writer.write(record);
        data.add(record);
    }

    out.deleteOnExit();
    Collection<Collection<Writable>> test = new ArrayList<>();
    RecordReader testLibSvmRecordReader = new LibSvmRecordReader();
    testLibSvmRecordReader.initialize(conf, new FileSplit(out));
    while (testLibSvmRecordReader.hasNext())
        test.add(testLibSvmRecordReader.next());
    assertEquals(data, test);

}

From source file:org.web4thejob.orm.CreateSchemaTest.java

@Test
public void schemaExportTest() throws IOException, SQLException {

    Log4jConfigurer.initLogging("classpath:org/web4thejob/conf/log4j.xml");

    Properties datasource = new Properties();
    datasource.load(new ClassPathResource(DatasourceProperties.PATH).getInputStream());

    final Configuration configuration = new Configuration();
    configuration.setProperty(AvailableSettings.DIALECT, datasource.getProperty(DatasourceProperties.DIALECT));
    configuration.setProperty(AvailableSettings.DRIVER, datasource.getProperty(DatasourceProperties.DRIVER));
    configuration.setProperty(AvailableSettings.URL, "jdbc:hsqldb:mem:mydb");
    configuration.setProperty(AvailableSettings.USER, datasource.getProperty(DatasourceProperties.USER));
    configuration.setProperty(AvailableSettings.PASS, datasource.getProperty(DatasourceProperties.PASSWORD));

    final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySettings(configuration.getProperties()).build();

    Connection connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();
    Statement statement = connection.createStatement();
    statement.executeUpdate("CREATE SCHEMA w4tj;");
    statement.close();/* w w w  .  ja  v  a  2  s.c o m*/

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        for (Resource resource : resolver.getResources("classpath*:org/web4thejob/orm/**/*.hbm.xml")) {

            if (resource.getFile().getName().equals("AuxiliaryDatabaseObjects.hbm.xml"))
                continue;

            configuration.addFile(resource.getFile());
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

    SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration);
    schemaExport.execute(Target.EXPORT, SchemaExport.Type.CREATE);

    if (!schemaExport.getExceptions().isEmpty()) {
        throw new RuntimeException((Throwable) schemaExport.getExceptions().get(0));
    }

}

From source file:org.web4thejob.joblet.base.AbstractORMTest.java

@Before
public void setUp() {

    if (!initialized && !ContextUtil.getSystemJoblet().isInstalled()) {
        Properties datasource = new Properties();
        try {//from w w w  .j av a2 s  . c  o m
            datasource.load(new ClassPathResource(DatasourceProperties.PATH).getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

        JobletInstaller jobletInstaller;
        jobletInstaller = ContextUtil.getBean(JobletInstaller.class);
        jobletInstaller.setConnectionInfo(datasource);
        List<Exception> errors = jobletInstaller.installAll();
        if (!errors.isEmpty()) {
            throw new RuntimeException("Test Context initialization failed.");
        }
        initialized = true;
    }

    ContextUtil.getMRS().refreshMetaCache();

}

From source file:de.tudarmstadt.ukp.wikipedia.wikimachine.factory.SpringFactory.java

private static XmlBeanFactory getBeanFactory() {
    File outerContextFile = new File(OUTER_APPLICATION_CONTEXT);
    boolean outerContextFileProper = outerContextFile.exists() && outerContextFile.isFile()
            && outerContextFile.canRead();
    Resource res = (outerContextFileProper) ? new FileSystemResource(outerContextFile)
            : new ClassPathResource(INNER_APPLICATION_CONTEXT);
    return new XmlBeanFactory(res);
}

From source file:org.craftercms.commerce.client.itest.data.MongoTestDataService.java

public void createTestData() throws Exception {
    Resource resource = new ClassPathResource(TEST_DATA_FILE);
    File file = resource.getFile();

    //Order order = mapper.readValue(file, Order.class);
    //mongoTemplate.save(order, Order.class.getName());

    //      Set<Order> orders = mapper.readValue(file, new TypeReference<Set<Order>>() {});
    //      mongoTemplate.insert(orders, Order.class.getName());

    LOGGER.info("Finished creating Mongo test data.");
}

From source file:com.consol.citrus.admin.service.TestCaseServiceTest.java

@Test
public void testGetTestPackages() throws IOException {
    reset(project);//from www.j a v  a 2s .  c  o m
    when(project.getSettings()).thenReturn(new ProjectSettings());
    String projectHome = new ClassPathResource("projects/sample").getFile().getAbsolutePath();
    when(project.getProjectHome()).thenReturn(projectHome);
    when(project.getJavaDirectory()).thenReturn(projectHome + "/src/test/java/");

    List<TestGroup> testPackages = testCaseService.getTestPackages(project);
    Assert.assertNotNull(testPackages);
    Assert.assertEquals(testPackages.size(), 5L);
    assertTestPackage(testPackages, "javadsl", 4L);
    assertTestPackage(testPackages, "foo", 2L);
    assertTestPackage(testPackages, "bar", 2L);
    assertTestPackage(testPackages, "com.consol.citrus.bar", 2L);
    assertTestPackage(testPackages, "com.consol.citrus.bar.scan", 1L);

    assertTestPresent(testPackages.get(0).getTests(), "CitrusJavaTest.fooTest", "CitrusJavaTest", "fooTest");
    assertTestPresent(testPackages.get(0).getTests(), "BarJavaTest", "CitrusJavaTest", "barTest");
    assertTestPresent(testPackages.get(0).getTests(), "DataProviderJavaTest.fooProviderTest",
            "DataProviderJavaTest", "fooProviderTest");
    assertTestPresent(testPackages.get(0).getTests(), "BarProviderTest", "DataProviderJavaTest",
            "barProviderTest");
    assertTestPresent(testPackages.get(1).getTests(), "FooTest", "FooTest", "FooTest");
    assertTestPresent(testPackages.get(1).getTests(), "WithoutLastUpdatedOnTest", "WithoutLastUpdatedOnTest",
            "withoutLastUpdatedOnTest");
    assertTestPresent(testPackages.get(2).getTests(), "BarTest", "BarTest", "barTest");
    assertTestPresent(testPackages.get(2).getTests(), "Bar2Test", "BarTest", "bar2Test");
    assertTestPresent(testPackages.get(3).getTests(), "BarPackageTest", "BarTest", "barPackageTest");
    assertTestPresent(testPackages.get(3).getTests(), "barPackageNameTest", "BarTest", "barPackageNameTest");
    assertTestPresent(testPackages.get(4).getTests(), "barPackageScanTest", "BarTest", "barPackageScanTest");
}

From source file:com.qq.tars.service.admin.AdminService.java

public AdminService() {
    String path = null;//  www . ja  v  a 2  s.  com
    try {
        path = new ClassPathResource("tars.conf").getFile().getCanonicalPath();

        CommunicatorConfig cfg = new CommunicatorConfig();
        cfg.load(Config.parseFile(path, Charset.forName("UTF-8")));
        communicator = CommunicatorFactory.getInstance().getCommunicator(cfg);
    } catch (Exception e) {
        log.error("init error, path={}", path, e);
        throw new RuntimeException(e);
    }
}

From source file:ch.algotrader.dao.AbstractDaoTest.java

@BeforeClass
public static void setupDB() throws Exception {

    DATABASE = new EmbeddedTestDB(new ClassPathResource("ch/algotrader/entity/GenericItem.hbm.xml"));
}