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:io.bosh.client.AbstractDirectorTest.java

protected String payload(String filename) {
    ClassPathResource resource = new ClassPathResource(filename);
    try {// ww w  .  java2 s.c  o  m
        return FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    } catch (IOException e) {
        throw new RuntimeException("TEST SETUP ERROR: unable to find test resources file with name " + filename,
                e);
    }

}

From source file:org.springsource.tutorial.util.DBInitializer.java

/** 
 * {@inheritDoc}// ww  w.j  av  a 2 s.  com
 */
@Override
public void afterPropertiesSet() throws Exception {
    Resource jsonResource = new ClassPathResource("usstates.json");
    ObjectMapper mapper = new ObjectMapper();
    TypeReference<List<USState>> ref = new TypeReference<List<USState>>() {
    };
    List<USState> states = mapper.readValue(jsonResource.getInputStream(), ref);
    TransactionStatus status = tm.getTransaction(null);
    for (USState state : states) {
        state.persist();
    }
    tm.commit(status);
}

From source file:org.sakaiproject.metaobj.utils.mvc.impl.beans.AdditionalHibernateMappings.java

public void setMappingResources(String[] mappingResources) {
    this.mappingLocations = new Resource[mappingResources.length];
    for (int i = 0; i < mappingResources.length; i++) {
        this.mappingLocations[i] = new ClassPathResource(mappingResources[i].trim());
    }/*www .  j  a  va  2  s.c  o m*/
}

From source file:com.epam.ta.reportportal.ws.MultipartRequestTest.java

@Test
public void testPageableLast() throws Exception {
    Resource multipartFile = new ClassPathResource(DEMO_FILE_NAME);
    MockMultipartFile mockMultipartFile = new MockMultipartFile(DEMO_FILE_NAME, multipartFile.getInputStream());

    this.mvcMock//from   w w  w .j  av  a2 s  .  c  om
            .perform(fileUpload(PROJECT_BASE_URL + "/log").file(mockMultipartFile).secure(true)
                    .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
            .andExpect(status().is(400));

}

From source file:org.canova.cli.driver.TestCommandLineInterfaceDriver.java

@Test
public void testMainCLIDriverEntryPoint() throws Exception {

    String[] args = { "vectorize", "-conf", "src/test/resources/csv/confs/unit_test_conf.txt" };

    CommandLineInterfaceDriver.main(args);

    String outputFile = "csv/data/uci_iris_sample.txt";

    ArrayList<String> vectors = new ArrayList<>();

    Map<String, Integer> labels = new HashMap<>();
    List<String> lines = FileUtils.readLines(new ClassPathResource(outputFile).getFile());
    for (String line : lines) {
        // process the line.
        if (!line.trim().isEmpty()) {
            vectors.add(line);// w w w .  java2 s .com

            String parts[] = line.split(" ");
            String key = parts[0];
            if (labels.containsKey(key)) {
                Integer count = labels.get(key);
                count++;
                labels.put(key, count);
            } else {
                labels.put(key, 1);
            }

        }
    }

    assertEquals(12, vectors.size());
    assertEquals(12, labels.size());
    File f = new File("/tmp/iris_unit_test_sample.txt");
    f.deleteOnExit();
    assertTrue(f.exists());

}

From source file:guru.qas.martini.gherkin.DefaultMixologyTest.java

@Test
public void testMixology() throws IOException {
    Resource resource = new ClassPathResource("/subsystem/sample.feature");
    Iterable<Recipe> recipes = factory.get(resource);

    int recipeCount = Iterables.size(recipes);
    assertEquals(1, recipeCount, "wrong number of Recipe objects returned");
}

From source file:nl.flotsam.calendar.core.CalendarParserTest.java

@Test
public void shouldParseMeetupICalCorrectly() throws IOException, ParserException {
    UnfoldingReader reader = new UnfoldingReader(
            new InputStreamReader(new ClassPathResource("test.ical").getInputStream(), "UTF-8"), 3000);
    Calendar calendar = new CalendarBuilder().build(reader);
}

From source file:de.extra.client.starter.ExtraClientParametersTest.java

@Test
public void testExtraClientParameters() throws Exception {
    final List<String> errors = Collections.<String>emptyList();

    final Resource globalConfigDir = new ClassPathResource("/testglobalconfig");
    final File globalConfigPath = globalConfigDir.getFile();

    final Resource configDir = new ClassPathResource("/testconfig");
    final File configPath = configDir.getFile();

    final Resource logDir = new ClassPathResource("/testlog");
    final File logPath = logDir.getFile();

    final Resource backupDir = new ClassPathResource("/testBackup");
    final File backupPath = backupDir.getFile();

    final ExtraClientParameters parameters = new ExtraClientParameters("mandant", globalConfigPath, configPath,
            logPath, "outputConfirm", "outputFailure", backupPath, false, false, errors);

    assertFalse(parameters.getShowHelp());

    assertEquals(globalConfigPath, parameters.getGlobalConfigurationDirectory());
    assertEquals(configPath, parameters.getConfigurationDirectory());
    assertEquals(logPath, parameters.getLogDirectory());
    assertEquals(errors, parameters.getErrors());
    assertEquals(backupPath, parameters.getBackupDirectory());
    assertEquals(true, parameters.shouldCreateBackup());
    assertEquals("mandant", parameters.getMandant());
    assertEquals("outputConfirm", parameters.getOutputConfirm());
    assertEquals("outputFailure", parameters.getOutputFailure());
}

From source file:com.wavemaker.tools.project.upgrade.swamis.WebInfActiveGridUpgradeTest.java

public void testWebInfUpgrade() throws Exception {

    StudioFileSystem fileSystem = new LocalStudioFileSystem();

    File sourceProjectRoot = new ClassPathResource(
            "com/wavemaker/tools/project/upgrade/swamis/webinfactivegridupgrade/").getFile();
    assertTrue(sourceProjectRoot.exists());

    File projectRoot = IOUtils.createTempDirectory("testWebInfUpgrade", "_dir");
    fileSystem.copyRecursive(new FileSystemResource(sourceProjectRoot.getAbsolutePath()),
            new FileSystemResource(projectRoot.getAbsolutePath() + "/"), new ArrayList<String>());
    // FileUtils.copyDirectory(sourceProjectRoot, projectRoot);

    Project p = new Project(new FileSystemResource(projectRoot.getAbsolutePath() + "/"),
            new LocalStudioFileSystem());
    File webinf = p.getWebInf().getFile();
    assertTrue(webinf.exists());/*from   ww w . j av  a  2  s.c om*/

    File servicesConfig = new File(webinf, ConfigurationCompiler.RUNTIME_SERVICES);
    File managersConfig = new File(webinf, ConfigurationCompiler.RUNTIME_MANAGERS);
    File webxml = new File(webinf, ProjectConstants.WEB_XML);
    assertTrue(servicesConfig.exists());
    assertTrue(managersConfig.exists());
    assertTrue(webxml.exists());

    String webxmlContents = FileUtils.readFileToString(webxml);
    assertTrue(webxmlContents.contains("com.activegrid.runtime.server.CleanupListener"));
    assertFalse(webxmlContents.contains("com.wavemaker.runtime.server.CleanupListener"));

    WebInfActiveGridUpgrade upgrade = new WebInfActiveGridUpgrade();
    UpgradeInfo upgradeInfo = new UpgradeInfo();
    upgrade.doUpgrade(p, upgradeInfo);
    assertEquals("verbose was: " + upgradeInfo.getVerbose() + ", messages: " + upgradeInfo.getMessages(),
            "Removed com.activegrid references from web.xml\nRe-generated files: project-services.xml, project-managers.xml",
            upgradeInfo.getVerbose().get("-1.0").get(0));

    webxmlContents = FileUtils.readFileToString(webxml);
    assertFalse(webxmlContents.contains("com.activegrid.runtime.server.CleanupListener"));
    assertTrue(webxmlContents.contains("com.wavemaker.runtime.server.CleanupListener"));

    assertTrue(servicesConfig.exists());
    assertTrue(managersConfig.exists());

    String servicesConfigContents = FileUtils.readFileToString(servicesConfig);
    String managersConfigContents = FileUtils.readFileToString(managersConfig);

    assertFalse(servicesConfigContents.contains("activegrid"));
    assertFalse(managersConfigContents.contains("activegrid"));
}

From source file:se.kth.csc.config.ApplicationConfig.java

/**
 * The provider for placeholders that lets us use {@link org.springframework.beans.factory.annotation.Value}
 * annotations elsewhere in the application.
 *//*www  .j  av  a2s . com*/
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer(Environment environment) {
    PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();

    // Load properties from "settings.properties"
    ppc.setLocation(new ClassPathResource("/settings.properties"));

    log.info("Creating placeholder configurer based on \"settings.properties\" file");
    return ppc;
}