Java 类org.springframework.core.io.ClassRelativeResourceLoader 实例源码

项目:spring4-understanding    文件:EmbeddedDatabaseBuilderTests.java   
@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();
    }
}
项目:spring4-understanding    文件:EmbeddedDatabaseBuilderTests.java   
@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();
}
项目:sharding    文件:ResourceLoader.java   
public static Resource getResource(String sourcePath) {
    String pathToUse = StringUtils.cleanPath(sourcePath);
    if (pathToUse == null) {
        return null;
    }
    Resource resource = null;
    try {
        if (pathToUse.startsWith(org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX)) {
            resource = new ClassRelativeResourceLoader(ResourceLoader.class).getResource(pathToUse);
        }
        if (resource == null) {
            resource = new FileSystemResourceLoader().getResource(pathToUse);
        }
    } catch (Exception e) {
        log.error("getResource error.", e);
    }
    return resource;
}
项目:class-guard    文件:EmbeddedDatabaseBuilderTests.java   
@Test
public void testBuildDerby() {
    Assume.group(TestGroup.LONG_RUNNING);

    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
    EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.DERBY).addScript("db-schema-derby.sql").addScript("db-test-data.sql").build();
    assertDatabaseCreatedAndShutdown(db);
}
项目:class-guard    文件:EmbeddedDatabaseBuilderTests.java   
@Test
public void testBuild() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
    EmbeddedDatabase db = builder.addScript("db-schema.sql").addScript("db-test-data.sql").build();
    assertDatabaseCreatedAndShutdown(db);
}
项目:class-guard    文件:EmbeddedDatabaseBuilderTests.java   
@Test
public void testBuildWithComments() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
    EmbeddedDatabase db = builder.addScript("db-schema-comments.sql").addScript("db-test-data.sql").build();
    assertDatabaseCreatedAndShutdown(db);
}
项目:class-guard    文件:EmbeddedDatabaseBuilderTests.java   
@Test
public void testBuildH2() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
    EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2).addScript("db-schema.sql").addScript("db-test-data.sql").build();
    assertDatabaseCreatedAndShutdown(db);
}